Frage

I have multiple NSPersistentStoreCoordinator instances that have just one NSPersistentStore each, all pointing to the same sqlite file. And in my testing passing NSManagedObjectID objects between them, and then calling

- (NSManagedObject *)existingObjectWithID:(NSManagedObjectID *)objectID error:(NSError **)error

on NSManagedObjectContext seems to work fine, but I have yet to come across any documentation from apple that confirms that this is supposed to work fine.

So, my question is, if anyone knows if this is supposed to work (a link to some apple documentation confirming it would be awesome!), of if anybody knows that this is not usually supposed to work, and that I should not be doing this, that would be awesome too!

War es hilfreich?

Lösung

It's always safe to call that method. Whether it returns an object is another story.

When using an object ID from a different context, you'll only get a non-nil result if the object is already accessible to the context you call this method on. That implies that the object already exists in the persistent store, meaning it has already been saved on its original managed object context.

Or in other words, you'll only get a non-nil result if you've already saved the object with the ID, and if you're using the object's permanent (post-save) ID.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top