• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Creating temporary NSManagedObjects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating temporary NSManagedObjects


  • Subject: Re: Creating temporary NSManagedObjects
  • From: vincent habchi <email@hidden>
  • Date: Mon, 26 Apr 2010 11:31:48 +0200

Jack,

> 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];

So, just replacing the MOC by nil. I have not tried that, I admit.

> 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".

Yes. But, at the same time, no doc on Core Data, whether Apple written or not, seems to talk about "temporary" objects, other than transient. Therefore, one might also infer that "initWithEntity:insertIntoManagedObjectContext:" is the designated initializer as far as you want your object to be inserted into the MOC…

Cheers, and thanks a lot for the idea!
Vincent_______________________________________________

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

References: 
 >Creating temporary NSManagedObjects (From: vincent habchi <email@hidden>)
 >Re: Creating temporary NSManagedObjects (From: Jack Nutting <email@hidden>)

  • Prev by Date: Re: Creating temporary NSManagedObjects
  • Next by Date: Re: Creating temporary NSManagedObjects (PS)
  • Previous by thread: Re: Creating temporary NSManagedObjects
  • Next by thread: Re: Creating temporary NSManagedObjects (PS)
  • Index(es):
    • Date
    • Thread