InternationalCodingGuru
InternationalCodingGuru

Reputation: 2258

Hold Strong ref to Managed Object

If I have a strong reference to a ManagedObject, and then that ManagedObject gets deleted from the Context, will my strong reference to the ManagedObject still be valid?

Upvotes: 2

Views: 203

Answers (3)

Jesse Rusak
Jesse Rusak

Reputation: 57178

Yes, though if your managed object is a fault (either because you've never accessed any values in it, or because you've turned it back into a fault with refreshObject:mergeChanges:) then if you try to access any properties on your deleted object, it will throw an exception.

So, you should be careful to check for isDeleted or else listen for notifications (e.g. NSManagedObjectDidSaveNotification) and check to see if your object was deleted.

Upvotes: 2

Daij-Djan
Daij-Djan

Reputation: 50109

yes it will be valid. it should reflect that it is deleted. object.isDeleted

Upvotes: 1

johan
johan

Reputation: 6666

From what I've understood YES, thats the case.

Reference

Upvotes: 1

Related Questions