• 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: Using a Core Data model by itself
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Using a Core Data model by itself
      • From: Jerry Krinock <email@hidden>
References: 
 >Using a Core Data model by itself (From: Daryle Walker <email@hidden>)

  • Prev by Date: Using a Core Data model by itself
  • Next by Date: Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior
  • Previous by thread: Using a Core Data model by itself
  • Next by thread: Re: Using a Core Data model by itself
  • Index(es):
    • Date
    • Thread