1. 程式人生 > >Argument of '#selector' refers to instance method 'changeScale(byReactingTo:)' that is not exposed t

Argument of '#selector' refers to instance method 'changeScale(byReactingTo:)' that is not exposed t

swfit 4 的新特性,

今天編譯程式碼發現了這個問題,查了下,修正很簡單在相關類前加:

@objcMembers!

As of Swift 4 you'll start seeing the error "Argument of '#selector' refers to instance method 'firstPage()' that is not exposed to Objective-C", along with the proposed fix of "Add '@objc' to expose this instance method to Objective-C". What this means is that the Swift method in question isn't visible to Objective-C, which matters because UIBarButtonItem

 is Objective-C code.

While adding @objc to individual methods is a working solution, I expect most people will just shrug their shoulders and put @objcMembers before their class – that automatically exposes everything in the class to Objective-C, just like Swift 3 used to. So, modify the class definition to this: