Re: Protocol extensions returning self
Re: Protocol extensions returning self
- Subject: Re: Protocol extensions returning self
- From: "Jan E. Schotsman" <email@hidden>
- Date: Fri, 05 Feb 2016 10:46:18 +0100
On Feb 4, 2016, at 4:56 PM, Charles Jenkins wrote:
Supposedly in a protocol, “Self” is the class implementing the
protocol. So it seems to me that extension methods should be able to
have a return type of Self so they can return self, and thus have
the extension method behave the same as it would as if it were
defined in the class adopting the protocol.
I am not sure if this solves your particular problem, but in general
you must do this
protocol MyProtocol
{
typealias Element
}
extension MyProtocol where Element == Self
{
// use Element instead of Self
}
At least I have found this to work better in my use cases.
Jan E.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden