How can I deal with @objc inference deprecation with #selector() in Swift 4?

后端 未结 5 1635
遥遥无期
遥遥无期 2020-11-22 04:59

I\'m trying to convert my project\'s source code from Swift 3 to Swift 4. One warning Xcode is giving me is about my selectors.

For instance, I add a target to a butt

5条回答
  •  一生所求
    2020-11-22 05:35

    As Apple Official Documentation. you need to use @objc to call your Selector Method.

    In Objective-C, a selector is a type that refers to the name of an Objective-C method. In Swift, Objective-C selectors are represented by the Selector structure, and can be constructed using the #selector expression. To create a selector for a method that can be called from Objective-C, pass the name of the method, such as #selector(MyViewController.tappedButton(sender:)). To construct a selector for a property’s Objective-C getter or setter method, pass the property name prefixed by the getter: or setter: label, such as #selector(getter: MyViewController.myButton).

提交回复
热议问题