How to properly handle KVO notifications when a managed entity turns into a malfunction?

From docs :

When Core Data turns an object into an error, Key Observation (KVO) notification of changes (see "Key Value" Observation Programming Guide) for object properties. if you observe the properties of an object that turns into a malfunction, and the error is subsequently implemented, you will receive notification of changes for the property whose values ​​in fact have changed.

So, if an object turns into an error, does Core Data send KVO notifications for the changed properties? So should I always check isFault == NO before you are happy with the notification?

+3
source share
2 answers

This is one solution. The best solution would be to stop monitoring the object when it becomes a malfunction. In practice, with the exception of situations with low memory, you know when the object will turn into a malfunction and can plan it.

+5
source

isFaultnot reliable as it isFaultcan still return NO when KVO notifications are sent. To do this, check faultingState:

faultingState Returns a value indicating the failure state of the receiver.

  • (NSUInteger) faultingState The return value is 0 if the object is fully initialized as a managed object and does not go to or from another state, otherwise some other value.

, .

+7

Source: https://habr.com/ru/post/1749802/


All Articles