Reputation: 43
In my code, I am trying to access [NSManagedObject managedObjectContext]
but surprisingly it returns nil. The managed object is loaded because I already successfully accessed it's values using [NSManagedObject valueForKey:]
. Is there any case where managedObjectContext returns nil?
Upvotes: 0
Views: 1110
Reputation: 9075
Official documentation says:
May be
nil
if the receiver has been deleted from its context. If the receiver is a fault, accessing this property does not cause it to fire.
Upvotes: 0
Reputation: 736
I may be wrong, but for me managedObjectContext was also set to nil for NSManagedObject, when this object was turned into a fault, and I didn't have strong reference to its context.
Upvotes: 0
Reputation: 64428
If you initialize a managed object directly using init
without inserting it into a context, then it may have a nil context. If you insert it and pass a nil value for the context, it will have a nil context.
Upvotes: 1