• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
RE: Populating a new SQLite Core Data store with default data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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: Thu, 26 Feb 2009 09:02:10 -0500
  • Organization: JTA Enterprises LLC

> -----Original Message-----
> From: cocoa-dev-bounces+jmunson=email@hidden [mailto:cocoa-dev-
> bounces+jmunson=email@hidden] 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 (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

  • Follow-Ups:
    • Re: Populating a new SQLite Core Data store with default data
      • From: "I. Savant" <email@hidden>
References: 
 >RE: Populating a new SQLite Core Data store with default data (From: Ben Trumbull <email@hidden>)

  • Prev by Date: Re: NSComboBox Bindings
  • Next by Date: Re: noobie mem management problem
  • Previous by thread: RE: Populating a new SQLite Core Data store with default data
  • Next by thread: Re: Populating a new SQLite Core Data store with default data
  • Index(es):
    • Date
    • Thread