objcio / app-architecture

Sample Code of the App Architecture Book
https://www.objc.io/books/app-architecture
2.06k stars 306 forks source link

Workaround for bug when observing optionals with KVO #8

Open tkrajacic opened 6 years ago

tkrajacic commented 6 years ago

https://github.com/objcio/app-architecture/blob/ee561c7b804b0a91f2411123f7cd5c4190a1221d/Recordings-MVVM-C-less-rx/Recordings/PlayViewController.swift#L6-L8

This can be worked around with some funny casting:

let newValue = change.newValue ?? (nil as Any? as! Value)
onChange(newValue)

Then we can also observe optionals correctly.

Thanks to the awesome help of Jordan Rose of the Swift team for providing the workaround!