What is the simplest way to know that NSManagedObject instance is new and hasn't been persisted yet?
I've found isInserted
property, but开发者_StackOverflow中文版 what if I created object without inserting it into managed context? Maybe I can use ObjectID
somehow for such a purpose?
Is inserted should work fine, because you cannot create a managed object without inserting it. You could also use the isTemporaryID method on the objectID, which returns YES if the object was not yet inserted.
Keep in mind that inserted does not mean persisted. If you insert an object into a managed object context you must first save the context before the object will be persisted (and then in turn the object does not count as being inserted anymore).
精彩评论