Swift access control with target selectors

后端 未结 1 417
猫巷女王i
猫巷女王i 2020-12-08 02:07

Have a look at this example code:

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let letter         


        
相关标签:
1条回答
  • 2020-12-08 02:44

    you need @objc to expose a private method to objc runtime

    @objc private func buttonDidTap(button:UIButton!) {
        println(button.char)
    }
    

    From Xcode6 beta4 release notes

    Declarations marked private are not exposed to the Objective-C runtime if not otherwise annotated. IB outlets, IB actions, and Core Data managed properties remain exposed to Objective-C whatever their access level. If you need a private method or property to be callable from Objective-C (such as for an older API that uses a selector-based callback), add the @objc attribute to the declaration explicitly.! !

    0 讨论(0)
提交回复
热议问题