swfit 4 的新特性
今天编译代码发现了这个问题,查了下,修正很简单在相关类前加:
@objcMembers
class JKWLoginVC: UIViewController
{
}
或者在方法名前做修改
@objc func clickLoginBtn() {
}
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:
Swift4中引入了@objcMembers属性,用于解决Swift方法无法被Objective-C访问的问题。当使用UIBarButtonItem等Objective-C代码时,需在相关类或方法前添加此属性,确保其可见性。
4560

被折叠的 条评论
为什么被折叠?



