Re: Importing data with core-data
Re: Importing data with core-data
- Subject: Re: Importing data with core-data
- From: Marc Respass <email@hidden>
- Date: Sat, 4 Nov 2006 22:49:21 -0500
Shaun,
On Nov 4, 2006, at 7:12 AM, shaun bear wrote:
I am writing an application that needs to download a couple of
tables (with a
master- detail relationship) and then merge them in to an existing
core data sqlite
store. The download could be formatted as xml or CSV. Is it
possible to do this
using the coredata.dtd or would it make more sense to use a more
generic xml
tree structure to represent the master-detail relationship? Any
thoughts or suggestions
would be much appreciated.
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).
- (void)addItemsFromPlist:(id)plist toController:(NSArrayController *)
controller;
{
NSEnumerator *oe = [plist objectEnumerator];
NSDictionary *dictionaryItem = nil;
while(dictionaryItem = [oe nextObject]) {
NSManagedObject *mo = [[controller newObject] autorelease];
[mo setValuesForKeysWithDictionary:dictionaryItem];
[controller addObject:mo];
}
}
This is really fast even on my first generation MacBook Pro ;)
Hope this helps
Marc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden