0

I'd like to know if there's a way to directly insert an existing NSManagedObject into Core Data instead of creating a new one and filling its instance variables.

Edit: removing from the ManagedObjectContext won't work for me because I can't handle it when user presses the back button on the Navigation Bar. That's why I don't wanna insert it.

Thank you

Lucas
  • 6,675
  • 3
  • 25
  • 43

1 Answers1

0

It's kind of going beside the Core Data patterns, but it's possible. The code is smth like:

[yourObjectContext insertObject:unassociatedObjet];
NSError *error = nil;
[yourObjectContext save:&error];
//Check the error!

Perhaps, this discussion will be useful in your case also.

Community
  • 1
  • 1
makaron
  • 1,585
  • 2
  • 16
  • 30
  • Thank you! the link guided me to find the solution. Other important step is to insertIntoManagedObjectContext:nil Here's what I did: http://stackoverflow.com/questions/3256195/how-to-deal-with-temporary-nsmanagedobject-instances/6857026#6857026 – Lucas Jul 28 '11 at 09:49