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

前端 未结 4 1202
一生所求
一生所求 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:08

    Since Swift 2.2 / Xcode 7.3 there is a new way to use a selector: Selector("funcName") was changed to #selector(ClassName.funcName)

    Have a look at https://github.com/apple/swift-evolution/blob/master/proposals/0022-objc-selectors.md ,

    tl;dr;

    Replace Selector("Start") with #selector(YOUR_CLASS.Start)

    where YOUR_CLASS = class of target in given context.

    If you don't want to do it manually, Xcode provides easy fix itself by default, when you have the following situation, tap on the Yellow triangles ( sometimes required to tap/click multiple times ),

    it will give you suggestion:

    And if you select that suggestion, it will automatically update the selector:

提交回复
热议问题