RE: Populating a new SQLite Core Data store with default data
RE: Populating a new SQLite Core Data store with default data
- Subject: RE: Populating a new SQLite Core Data store with default data
- From: "Jon C. Munson II" <email@hidden>
- Date: Mon, 23 Feb 2009 13:35:14 -0500
- Organization: JTA Enterprises LLC
> >
>
> > By calling -setValue:forKey: one can then fill in the data values
> > for the required
> > attributes.
> >
> The documentation makes clear that you should typically *not* use key-
> value coding to set managed objects' attribute values:
> <http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articl
> es/cdUsingMOs.html#//apple_ref/doc/uid/TP40001803
> >
>
[Jon C. Munson II] The documentation states the following:
" You can also use key-value coding (KVC) to get or set the value of a
simple attribute as illustrated in the following code fragment."
It then goes on to say:
" Using KVC, though, is considerably less efficient than using accessor
methods, so you should only use KVC when necessary (for example when you are
choosing the key or keypath dynamically)."
The sample code I saw elsewhere used the KVC methodology, so that was what I
latched onto.
I'll change my code and use the dot syntax which appears to be most
efficient. Thank you for the pointer to that particular reference.
<a little later on...>
After some brief testing, if one creates entities of NSManagedObject thus:
NSManagedObject *someObject = [NSEntityDescription insert...];
one most likely cannot use the dot syntax accessors as someObject, during
compilation, has no idea of the attributes of that object an thus an error
will be thrown - it is generic and falls into the "dynamic" category stated
by the documentation.
You'll have to use KVC in that case. At least, I did. I tried both the dot
and standard accessor to be sure.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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