Swift: Property conforming to a specific class and in the same time to multiple protocols -


in objective-c, it's possible write that:

@property(retain) uiview<protocol1, protocol2, ...> *myview; 

but how can write code in swift?

i know how make property conform many protocols, not work using inheritance:

var myview: ??? protocol<protocol1, protocol2, ...> 

edit:

i use many uiview subtypes uiimageview, uilabel or others, , need use of uiview properties plus methods defined in protocols. in worst case create uiviewprotocol needed properties, know if possible in swift declare property/variable type , protocol conform with.

you can generic class using where clause:

a clause enables require associated type conforms protocol, and/or type parameters , associated types same.

to use it, make class property defined in generic class type constraint check if type parameter property matches desired base class , protocols.

for specific example, this:

class myviewcontroller<t t: uiview, t: protocol1, t: protocol2>: uiviewcontroller {     var myview: t      // ... } 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -