Re: Using Core Data NSManagedObject subclasses outside of a managed object context
Re: Using Core Data NSManagedObject subclasses outside of a managed object context
- Subject: Re: Using Core Data NSManagedObject subclasses outside of a managed object context
- From: Mike Abdullah <email@hidden>
- Date: Thu, 27 Aug 2009 12:55:10 +0100
Further to earlier answers, reread the docs on -[NSManagedObject
initWithEntity:managedObjectContext:]
There's nothing to stop you doing this:
NSManagedObject *object = [[NSManagedObject alloc]
initWithEntity:entity managedObjectContext:nil];
[object setFoo:bar];
as long as you supply a valid entity.
Mike.
On 24 Aug 2009, at 01:32, Dieterich Lawson wrote:
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
_______________________________________________
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