[swift-evolution] Specify type of a delegate which conforms to a protocol
2th at gmx.de
Wed Feb 10 09:56:13 CST 2016
>> 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.
right, normal parenthesis are already used...
>> 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.)
true as well — seems I've been quite dozy when I outlined those colliding syntaxes ;-)
However, I don't like grouping using brackets; how about
let controller: Optional<UIViewController & UITableViewDatasource>
As we have inout, the ampersand should still be available — and it would fit nicely with "|" for sum types (although I have no idea wether algebraic data types will be considered in the future)
More information about the swift-evolution