Re: core data newbie Q
Re: core data newbie Q
- Subject: Re: core data newbie Q
- From: "Marcus S. Zarra" <email@hidden>
- Date: Tue, 5 Jun 2007 12:13:54 -0600
You can store the incoming data in an NSMutableDictionary to avoid
creating a unnecessary and temporary class. As for the
NSManagedObject, at minimum you can create it in the model and use
the standard NSManagedObject and avoid creating a data class there
also. You only need to extend NSManagedObject for custom data
classes if you want to do something at the model level that is above
and beyond what is provided for in NSManagedObject. Therefore, to do
an import you would use:
NSMutableDictionary to hold each "record".
NSManagedObject to put the data into Core Data.
If your data is very flat you might even be able to avoid using the
dictionaries and stick the data directly into the NSManagedObjects.
This depends on the incoming data model.
Marcus S. Zarra
Zarra Studios LLC
Simply Elegant Software for OS X
www.zarrastudios.com
On Jun 5, 2007, at 12:08 PM, Daniel Child wrote:
Thanks for clearing that up. I was confusing the internal storage
format with data to import.
This seems to suggest that I have to create two classes: 1) a class
representing the data to be imported (probably storing in an array
of that class), and 2) an NSManagedObject which mirrors the class
and converts each object's instance variables into entity
attributes. Is that the standard approach, or am I still muddling
things up?
Thanks.
On Jun 5, 2007, at 9:38 AM, Andrew Kimpton wrote:
On Jun 5, 2007, at 9:24 AM, Daniel Child wrote:
Hi,
I have been reading up on the Core Data documentation. One thing
I don't see answered in the documentation is how you can import
data that is not in XML, SQLite, or binary format.
In other words, what steps would you take to import a comma- or
tab-delimited flat file.
Don't confuse the internal storage formats that CoreData uses with
what can be imported. The two are not connected, primarily because
importing data is entirely your responsibility. Your app needs to
parse the input file using NSScanner (or whatever other tools you
wish to use), create an NSManagedObject (or child class) instance,
using insertNewObjectForEntityName and then set the appropriate
values on it from the results of your parsing.
The Core Data Programming Guide has a section 'Efficiently
importing legacy data' which goes over some of the 'gotchas' that
you might run into (see also other recent posts about autorelease
pools and CoreData memory usage if you're importing thousands of
objects).
Andrew 8-)
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden