Candidate is not '@objc' but protocol requires it

后端 未结 4 541
余生分开走
余生分开走 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:25

    Add an extension to the protocol returning empty functions and default values. Any class that conforms to the protocol and wishes to override any func or var may optionally do so.

        public protocol Speaker {
          func Speak()
          func TellJoke()
        }
    
        extension Speaker {
          func Speak() {}
          func TellJoke() { print("What did the Teabag say to the Octopus?"}
        }
    

    The bonuses are you don't inherit all of the obj-c baggage.

提交回复
热议问题