• 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
protocol extension with SequenceType
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

protocol extension with SequenceType


  • Subject: protocol extension with SequenceType
  • From: Roland King <email@hidden>
  • Date: Thu, 09 Jul 2015 18:20:56 +0800

Failing to find a syntax which works to do this. What I’m trying to do here is extend Array to conform to a protocol. The real example has constraints on the Element of the Array, so I can’t just extend Array, I have to use a protocol extension on the protocol (I can’t find a way to extend Array to conform to a type and also have some constraints).

Since an Array is a SequenceType and that’s all I really need, I tried this, this is the very distilled version

protocol Foo
{
}

extension Foo where Self : SequenceType
{
	func bar()->Self
	{
		let retval : Array<Self.Generator.Element> = []
		return retval							// error: cannot convert return expression of type 'Array<Self.Generator.Element>' to expected return type 'Self'
	}
}

but I get the given error message and don’t see why (nor how to fix it). An Array is a SequenceType, so one should be returnable as a ‘Self’ as long as it’s an array of the right elements. Self.Generator.Element should be the correct element type for the array. Compiler bug or something I’m missing?
_______________________________________________

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


  • Follow-Ups:
    • Re: protocol extension with SequenceType
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: Anyone recommend Dash?
  • Next by Date: Re: How to resize accessory view to match Open panel
  • Previous by thread: Re: Anyone recommend Dash?
  • Next by thread: Re: protocol extension with SequenceType
  • Index(es):
    • Date
    • Thread