Feature request/suggestion: object conforming to a protocol type

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

This is part of the existential types and a highly wanted feature. You can read more about here and here.

···

--
Adrian Zubarev
Sent with Airmail

Am 21. November 2016 um 22:01:33, Richard Henry via swift-evolution (swift-evolution@swift.org) schrieb:

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
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution