Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I store a Core Data 'selected' item?

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?

like image 489
trapper Avatar asked Sep 04 '25 16:09

trapper


1 Answers

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.

like image 164
amattn Avatar answered Sep 07 '25 12:09

amattn