We Recommend

Programming in Objective-C Programming in Objective-C
Programming in Objective-C is a concise, carefully written tutorial on the basics of Objective-C and object-oriented programming. The book makes no assumption about prior experience with object-oriented programming languages or with the C language (upon which Objective-C is based). And because of this, both novice and experienced programmers alike can use this book to quickly and effectively learn the fundamentals of Objective-C.


Posted By

zingo on 10/11/07


Tagged

import cocoa coredata xml osx objc


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

tcol


Importing data with coredata


Published in: Objective C 


URL: http://www.cocoabuilder.com/archive/message/cocoa/2006/11/5/173980

A database table is basically an array of dictionary objects. As long
as all the fields are valid property list types, you can loop through
the array creating a managed object for each dictionary and setting
the values. If you have an array controller in your nib and it's
configured for your managed object, you can use this (where plist is
expected to be an NSArray* - not sure why I made it an id).


  1. - (void)addItemsFromPlist:(id)plist toController:(NSArrayController *)
  2. controller;
  3. {
  4. NSEnumerator *oe = [plist objectEnumerator];
  5. NSDictionary *dictionaryItem = nil;
  6. while(dictionaryItem = [oe nextObject]) {
  7. NSManagedObject *mo = [[controller newObject] autorelease];
  8. [mo setValuesForKeysWithDictionary:dictionaryItem];
  9. [controller addObject:mo];
  10. }
  11. }

Report this snippet 

You need to login to post a comment.