KVO crashes when observing keypath of object that changes across multiple threads

Originator:yaron
Number:rdar://48345603 Date Originated:
Status:Open Resolved:
Product:iOS Product Version:12.0
Classification:Foundation Reproducible:Yes
 
Area:
Foundation

Summary:
Observing an object with "deep" keypath (i.e. more than one key) while replacing the root object in multiple threads causes an exception to be raised and the app to crash, claiming that the observer cannot be updated.

Steps to Reproduce:
1. Create an object with a child object.
2. Observe changes to the child object via a keypath observation.
3. Change the root object from multiple threads.

Expected Results:
No crash, KVO reports changes as expected.

Actual Results:
Exception is raised.

Version/Build:
iOS 12.1 (XCode 10.1 10B61)

Configuration:
Works both on simulator and device.

Comments

Apple Developer Relations

Engineering has the following feedback for you:

This is expected in many cases; there is supposed to be no use of KVO between -willChangeValue… and -didChangeValue…, and no change in the visible value of the key that isn’t bracketed between these calls. Please ensure that entire sequence occurs atomically.

If you suspect your case should be supported given the above description, could you please send a sample project that shows the issue? Thank you.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!