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: Ben Trumbull <email@hidden>
- Date: Wed, 25 Feb 2009 23:29:46 -0800
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.
On 10.5 and later, all NSManagedObjects always respond to methods
matching the standard Cocoa conventions for setters and getters for
their entity's modeled properties.
If you have a model with an entity that has a "name" attribute, you
can just call -name or -setName:. Always.
The ObjC property notation is more of a stickler. You can type cast
to a specific subclass. Xcode's Design -> Data Model -> Copy ObjC 2.0
Method Declarations to Clipboard will do all the heavy lifting if you
add new properties to your entity. Just select the properties in the
data model you want property declaration for.
The only confusion here is that the type declarations have confused
the compiler. You ought to be doing:
MySubclass *someObject = [NSEntityDescription insert...];
- Ben
_______________________________________________
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