Types conforming to multiple protocols in swift

前端 未结 5 546
一整个雨季
一整个雨季 2020-12-13 11:43

I have an Objective-C variable that conforms to multiple protocols.

id  identityToken; 

How would I re

5条回答
  •  -上瘾入骨i
    2020-12-13 12:19

    The above answer from conner is correct, however you often should implement a separate protocol that itself inherits from the other protocols, and allows you more flexibility, should you want to add additional protocol methods later or change the top level protocols.

    internal protocol MyOtherProtocol : NSObjectProtocol, NSCopying, NSCoding {
        func someOtherNecessaryMethod()
    }
    

    Then utilized:

    var identityToken : MyOtherProtocol
    

提交回复
热议问题