Return to Snippet

Revision: 3975
at October 11, 2007 21:57 by zingo

Initial Code
- (void)addItemsFromPlist:(id)plist toController:(NSArrayController *)
   NSEnumerator *oe = [plist objectEnumerator];
   NSDictionary *dictionaryItem = nil;
   while(dictionaryItem = [oe nextObject]) {
       NSManagedObject *mo = [[controller newObject] autorelease];
       [mo setValuesForKeysWithDictionary:dictionaryItem];
       [controller addObject:mo];

Initial URL

Initial Description
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).

Initial Title
Importing data with coredata

Initial Tags
xml, osx

Initial Language
Objective C