[swift-users] Generic inheritance with where clause
somu subscribe
somu.subscribe at gmail.com
Tue Aug 29 20:25:16 CDT 2017
Hi Nikita,
See if the below implementation fits your needs:
protocol P1 {}
protocol P2 : P1 where T : P1 {
associatedtype T
var input : T { get }
}
struct S1 : P1 {}
struct S2 : P2 {
typealias T = S1
var input: T
}
Regards,
Muthu
> On 30 Aug 2017, at 1:25 AM, Nikita Leonov via swift-users <swift-users at swift.org> wrote:
>
> Hello everyone,
>
> I am looking a way to express something similar to the following code in Swift terms:
> protocol AnyViewModelInput {}
> protocol AnyViewModel<ViewModelInput>: ViewModelInput where ViewModelInput: AnyViewModelInput {
> var input: ViewModelInput { get }
> }
>
> Is it possible in current Swift? Will it be possible if generic manifesto will be implemented in full? Also if you know how to express a similar idea in any other language, I would love to see examples. How does such construct is named in other languages?
>
> Thank in advance,
> Nikita
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170830/202884e8/attachment.html>
More information about the swift-users
mailing list