3

My application needs to keep track of which managed object is currently selected. In memory this is easy, but the question is how do I do this when my application exits and restarts.

Can I write the object itself to NSUserDefaults and then retrieve it later (I think this wouldn't be the same object thou, just a copy) Or can I store the entity id somehow? Or is there another way I'm overlooking?

trapper
  • 11,716
  • 7
  • 38
  • 82

1 Answers1

3

Just store the NSManagedObjectID. You will likely have to store it as an NSString from the NSURL (URIRepresentation).

Also make sure it is NOT a temporary ID. When the app starts again, load the NSManagedObject from the NSURL from the string you saved.

amattn
  • 10,045
  • 1
  • 36
  • 33