Re: Using a Core Data model by itself
Re: Using a Core Data model by itself
- Subject: Re: Using a Core Data model by itself
- From: Jens Alfke <email@hidden>
- Date: Thu, 28 Apr 2016 13:23:54 -0700
> On Apr 28, 2016, at 10:56 AM, Daryle Walker <email@hidden> wrote:
>
> Can I use a CD model object without managed contexts nor persistent stores?
I’m pretty sure you can’t, but if you’re not doing anything fancy in your modeling, the classes will just be pretty vanilla classes with some properties.
So you can start out declaring the model classes like
@interface Message : NSObject <NSCoding>
@property NSString* subject;
@property Address* sender;
…
and implement the NSCoding methods to save and restore the persistent properties. Then you can save your “database” by archiving a root object that all your models are transitively reachable from, and reload the database by loading that archive.
When you move to Core Data, just change the declaration to
@interface Message : NSManagedObject
and in the implementation file take out the -initWithCoder: and -encodeWithCoder: methods. You’ll also need to add an “@dynamic” declaration for the persistent properties, so that NSManagedObject can bind them to the database.
—Jens
_______________________________________________
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