digital-horizon / RoundCoachMark

The Swift library for showing the rounded coach marks (useful for onboarding or run-time help purposes)
MIT License
69 stars 15 forks source link

Fix: SE-0054 related warnings #6

Closed jcridev closed 4 years ago

jcridev commented 4 years ago

SE-0054: https://github.com/apple/swift-evolution/blob/master/proposals/0054-abolish-iuo.md

Fixed the Coercion of implicitly unwrappable value of type 'NSObjectProtocol?' to 'Any' does not unwrap optional warnings.

Since the token field of CoachMarkHandler is marked as non-optional we can safely forcibly unwrap it wherever it's used.

The warning appears in XCode 11 because, as stated in SE-0054, ! is treated differently now in regards to IUO values.

Specifically:...the appearance of ! at the end of a property or variable declaration's type no longer indicates that the declaration has IUO type; rather, it indicates that (1) the declaration has optional type, and (2) the declaration has an attribute indicating that its value may be implicitly forced. ...

Hence even though var token:NSObjectProtocol! is declared with !, XCode will still prefer to bind it to an optional since NotificationCenter.default.removeObserver(...) accept Any value that can be nil. Hence, the annoying warning.