Xcode 7.3 / Swift 2: “No method declared with Objective-C selector” warning

前端 未结 4 1197
一生所求
一生所求 2020-12-05 06:17

I\'ve been using selectors for a while, and even after migrating to Swift I was able to use them without issues. That\'s how I was using on Swift 2 without issues until I up

4条回答
  •  天命终不由人
    2020-12-05 07:07

    On Swift 4 I had to add @objc before the func to get rid of the warnings.

    This is how I call the func with NSTimer:

     Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(ViewController.intro), userInfo: nil, repeats: false)
    

    This is how the func is declared:

         @objc func intro () {
    
              // do your stuff here         
    
         }
    

    I also updated the setting as the Xcode requested:

    No more warnings, everything seems to be working fine.

提交回复
热议问题