Re: Creating temporary NSManagedObjects
Re: Creating temporary NSManagedObjects
- Subject: Re: Creating temporary NSManagedObjects
- From: Jack Nutting <email@hidden>
- Date: Mon, 26 Apr 2010 11:04:46 +0200
On Mon, Apr 26, 2010 at 10:43 AM, vincent habchi <email@hidden> wrote:
> I need to create a short-lived NSManagedObject; ideally, I'd want it not to be inserted in the Core Data underlying framework, because I need it only during the display of an auxiliary window, and I don't want it saved anyway. I've tried a simple alloc, an alloc and init, but to no avail: It seems to create only the proxy object. Is there a way to do that?
>
> Thanks,
> Vincent_______________________________________________
What you want to do, probably, is create an object that doesn't belong
to a context (the context is what ends up saving your object to a data
store). You should be able to do something like this:
// assuming your app delegate contains the "managedObjectModel" method, which
// the standard Xcode-generated CoreData app typically does
NSManagedObjectModel *managedObjectModel = [[NSApplication delegate]
managedObjectModel];
NSEntityDescription *entity = [[managedObjectModel entitiesByName] @"MyEntity"];
id obj = [[NSManagedObject alloc] initWithEntity:entity
insertIntoManagedObjectContext:nil];
BTW the docs for NSManagedObject clearly state that
"initWithEntity:insertIntoManagedObjectContext:" is the designated
initializer to use for creating instances, and that you shouldn't just
call "init".
--
// jack
// http://nuthole.com
// http://learncocoa.org
_______________________________________________
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