[SR-4522] #keyPath broken for isFinished
property of Operation in Swift 3.1
#47099
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Environment
Xcode Version 8.3 (8E162) running on Sierra
Additional Detail from JIRA
md5: af6b518132a5511470360293bde4eb21
duplicates:
Issue Description:
This UIViewController code worked back in Xcode 8.2, Swift 3:
In Xcode 8.3, Swift 3.1, that same code now crashes with "[object] deallocated while key value observers were still registered with it." Our `observeValue` is not being called!
I have not found any way to get `observeValue` to be called for the `finished` / `isFinished` property while using `#keyPath` syntax. The only workaround I have found is to revert to a raw string:
That solves the problem from a practical standpoint, but we are forced to give up the yummy goodness of `#keyPath`.
I believe the source of the problem is that there is something odd about NSOperation's `isFinished` KVO-observable property, but I don't know exactly what it is. It seems to have something to do with the `is` prefix. Swift 3.1 now insists on translating `#keyPath(isFinished)` into "finished", which is clever but wrong in the case of NSOperation — you must use a keypath of "isFinished" (even in Objective-C) or the KVO notification won't fire.
The text was updated successfully, but these errors were encountered: