Drew McCormack Drew McCormack - 7 months ago 51
Swift Question

Types conforming to multiple protocols in swift

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

id <NSObject, NSCopying, NSCoding> identityToken;

How would I represent this type in Swift?


This should work:

var identityToken : protocol<NSObjectProtocol, NSCopying, NSCoding>

Note you have to use NSObjectProtocol instead of NSObject in swift.

Here are some additional examples:

Array of objects conforming to multiple protocols:

var array: [protocol<NSObjectProtocol, NSCopying, NSCoding>]

Function with a parameter that conforms to multiple protocols:

func foo(param: protocol<NSObjectProtocol, NSCopying, NSCoding>) {