FROM : Marc Respass
DATE : Sun Nov 05 04:49:21 2006
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
DATE : Sun Nov 05 04:49:21 2006
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
| Related mails | Author | Date |
|---|---|---|
| shaun bear | Nov 4, 13:12 | |
| Marc Respass | Nov 5, 04:49 |






Cocoa mail archive

