views:

89

answers:

1

I would like to use a single NSManagedObject subclass to represent an item. However, much of the time, the items I will be representing are fleeting, and are not to be saved to the persistent store. It seems like an in-memory store would be the correct setup.

However a few times the user can choose to 'save' an item, and thus I would then like that item to be persisted to a SQLite store.

It seems as though I need two stores. Do I need two contexts? Is there a recommended way to move an item from the in-memory store to the 'saved' persistent store? Any other suggestions or issues people can recommend when mixing persistent and non-persistent managed objects of the same type?

A: 

You can have multiple persistent stores for a single persistent store coordinator. Use -[NSManagedObjectContext assignObject: toPersistentStore:] to choose which store an object is associated with. So your transient objects would get assigned to the in-memory store.

Graham Lee