> -----Original Message-----
> From: cocoa-dev-bounces+jmunson=his....@lists.apple.com [mailto:cocoa-dev-
> bounces+jmunson=his....@lists.apple.com] On Behalf Of Ben Trumbull
> Sent: Thursday, February 26, 2009 2:30 AM
> To: Cocoa Developers
> Subject: RE: Populating a new SQLite Core Data store with default data
> 
> > 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
> 

[Jon C. Munson II] And, yes, that is exactly what I ended up doing:

Declared @class "someEntityClass" in .h file.  Added #import
"someEntityClass.h" in .m file.  Then:

        someEntityClass *someObject = [NSEntityDescription insert...];
        someObject.attribute = @"";
        ...
        // lather, rinse, repeat for as many attributes and "instances" of
that object
      // that need creation

        [MOC save:NULL];  // at some point save what was created

Interestingly enough, as I wanted my objects inserted in a particular order,
I had to call save after each insertion (no big deal as I don't have that
many records and this is a one-time thing) - the MOC didn't save the records
in the order I had created them, but inserted them in no particular order
(at least from the tool I used to examine the tables).  Despite the -save
being called, a few were still out of order, but not critically so.

Thank you for the confirmation Ben!

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to