[swift-evolution] Feature request/suggestion: object conforming to a protocol type

Richard Henry richardhenry at me.com
Mon Nov 21 15:01:23 CST 2016


Hopefully this is the right mailing list...

It seems like there’s currently no way to declare a type that is an object conforming to a protocol in Swift, and I think that would be a useful language feature to add.

To be super clear about what I mean, if I have the following code:

   class MyClass {
       …
   }

   protocol MyProtocol {
       …
   }

There is currently no way to do something like (in pseudo-code):

   var thing: MyClass & MyProtocol = …

In Objective-C, you would do:

   MyClass <MyProtocol> *thing ...

Is this up for consideration, or is there a reason why this isn’t possible? Thanks.

Richard


More information about the swift-evolution mailing list