Drew McCormack Drew McCormack - 1 year ago 113
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?

Answer Source

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>) {

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download