• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Protocol extensions returning self
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Re: How to know if an NSView has pending draws
  • Next by Date: WebViews and the Java Plugin
  • Previous by thread: Re: Protocol extensions returning self
  • Next by thread: Weird Problem, is this an XCode Bug?
  • Index(es):
    • Date
    • Thread