Candidate is not '@objc' but protocol requires it

后端 未结 4 550
余生分开走
余生分开走 2021-02-13 22:33

I have been following this tutorial to learn swift & iOS app development. In the Protocol section, the tutorial defined the following protocol:

@objc protoco         


        
4条回答
  •  余生分开走
    2021-02-13 23:27

    Looks like we only need to prefix protocol method with @objc in private class.

    private class A: NSObject, SomeObjcProtocol {
      @objc func someProtocolMethod() {}
    }
    

    Warning is not likely to rise for non-private class.

    class A: NSObject, SomeObjcProtocol {
      func someProtocolMethod() {}
    }
    

    Both are fine.

提交回复
热议问题