Reputation: 25983
I'm building an app which receives a number of listings from a web API, and allows the user to save some for offline viewing. My usual approach would be:
But this is a Core Data app, so the context is what gets saved, not the object. Under those circumstances, the above would become something like this:
One approach to having an unmanaged and a managed version of Listing objects would be to have two classes, e.g. ManagedListing and UnmanagedListing - but that's a horribly repetitive way of doing it.
What I'd like is to make Listing a subclass of NSManagedObject; initialise a bunch of them without an NSManagedObjectContext; then when I want to save one, I either set its context or I copy its attributes to a new Listing inside a context.
Can I make instances of an NSManagedObject in no particular NSManagedObjectContext? If so, how?
Upvotes: 2
Views: 616
Reputation: 299345
Use two persistent stores, one in memory and one on disk. If the user wants to save, move the object to the other store using assignObject:toPersistentStore:
.
Upvotes: 7