开发者

How to properly deal with KVO notifications when an managed object turns into a fault?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜