protocol extension with SequenceType
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