[swift-evolution] Specify type of a delegate which conforms to a protocol

Inder Kumar Rathore . rathore619 at gmail.com
Thu Feb 11 00:32:12 CST 2016


I'm somewhat convinced with Maximilian

for

*protocol<MyProtocol where Self: UIViewController>*

Brent also has a valid point of having at least one class type in the
protocol

protocol<OneClass, OtherProtocol, SomeProtocol>


On Wed, Feb 10, 2016 at 10:56 PM, Jordan Rose via swift-evolution <
swift-evolution at swift.org> wrote:

>
> > On Feb 10, 2016, at 5:00 , Brent Royal-Gordon via swift-evolution <
> swift-evolution at swift.org> wrote:
> >
> >> So, I definitely think there is room for improvement hereā€¦ how about
> recycling the inheritance syntax?
> >>
> >> let controller: (UIViewController, UITableViewDatasource)
> >
> > This declares a tuple containing a UIViewController and a
> UITableViewDataSource.
> >
> >> I added the braces because it would be really when you add the question
> mark for an optional value; an alternative for this case would be
> >>
> >> let controller: Optional<UIViewController, UITableViewDatasource>
> >
> > This attempts to declare an optional with two generic types, which
> doesn't work because Optional only has one type parameter. (But other
> types, like Dictionary, *do* take two type parameters.)
> >
> > Swift does already have a syntax for declaring that a type must conform
> to two (or more!) protocols:
> >
> >       let controller: protocol<UITableViewDataSource,
> UITableViewDelegate>
> >
> > I think this could probably be extended to support one class type as
> well, perhaps with a new name:
> >
> >       let controller: all<UIViewController, UITableViewDataSource>
>
> We've been calling it "any" or "Any" (as in "any instance that is-a
> UIViewController and is-a UITableViewDataSource"), but I think this is the
> direction we've been talking about over here.
>
> (Not that syntax bikeshedding can't still be useful.)
>
> Jordan
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>



-- 
Best regards,
Inder Kumar Rathore
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160211/f602a1b6/attachment.html>


More information about the swift-evolution mailing list