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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/cocoadev%40mikeabdullah.net

This email sent to cocoa...@mikeabdullah.net

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to