Using Core Data NSManagedObject subclasses outside of a managed object context
Using Core Data NSManagedObject subclasses outside of a managed object context
- Subject: Using Core Data NSManagedObject subclasses outside of a managed object context
- From: Dieterich Lawson <email@hidden>
- Date: Sun, 23 Aug 2009 19:32:45 -0500
Hey all,
I have objects that I use with core data that were automatically generated
for me by xcode and represent entities in my data store. They all subclass
NSManagedObject, and do not have instance variables, but instead use the
@dynamic setting for their properties, pretty standard. My understanding is
that this allows the NSManagedObject superclass to generate the
getters/setters at runtime and store data in it's own, more efficient, Core
Data friendly way.
What this means for me, however, is that I can't just call [[Entity alloc]
init] and then get/set Entity's properties, because it won't properly
initialize unless it is given a managed object context. I need to be able to
use my objects in places that they won't be persisted, as just transient
objects, but this prevents that. The only way I know to initialize them is
by calling [NSEntityDescription insertNewObjectForEntityForName:name
inManagedObjectContext:managedObjectContext] . But, when creating objects
this way, they will be persisted on the next save call.
Does anyone know of a way to modify the objects so that I can use them
wherever I want without having to insert them into a managed object context?
I've read different places that you shouldn't do what I'm trying to do, but
if Core Data doesn't allow you to use its objects without persisting them,
then that would be a major shortcoming for me. Are there architectural
changes I can make that would overcome this?
Just so you know, I'm making a feed reader that has the option to save
selected stories from the feed for later, offline, browsing. I want to be
able to download the feed XML and create 'story' objects from that without
having to persist every story I fetch.
_______________________________________________
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