From the docs:
When Core Data turns an object into a fault, key-value observing (KVO) change notifications (see Key-Value Observing Programming Guide) are sent for the object’s properties. If you are observing properties of an object that is turned into a fault and the fault is subsequently realized, you receive change notifications for properties whose values have not in fact changed.
So if an object turns into a fault, Core Data does send KVO notifications for changed properties? So I must always check for isFault == NO before beeing happy about the notification?
isFault
is not reliable because isFault
may still returns NO when KVO notifications are sent. One should check faultingState
for that:
faultingState Returns a value that indicates the faulting state of the receiver.
- (NSUInteger)faultingState Return Value 0 if the object is fully initialized as a managed object and not transitioning to or from another state, otherwise some other value.
Discussion The method allow you to determine if an object is in a transitional phase when receiving a key-value observing change notification.
That is one solution. A better solution would be to stop observing the object when it gets turned into a fault. In practice, except for in low memory situations, you know when an object is going to be turned into a fault and can plan for it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With