Any way around the 'typealias' requirement here
Any way around the 'typealias' requirement here
- Subject: Any way around the 'typealias' requirement here
- From: Roland King <email@hidden>
- Date: Fri, 26 Jun 2015 10:49:07 +0800
Trying to have a delegate pattern with a typealias requirement. I can define the protocol, I can make a class conform to it, but I can’t declare a variable of that type as a member of another class because it has associated type information. Is there a way to do this, or is there a very good reason what I’m trying to do doesn’t make sense?
public protocol Foo : class
{
typealias Key
func foo( k : Key )->()
}
public class FooClass : Foo
{
typealias Key = Int
public func foo( k : Int )->() // satisfies the protocol requirement
{
print( "Satisfies Foo" )
}
}
public class Bar<Key>
{
var delegate : Foo // Protocol ‘Foo’ can only be used as a generic constraint because …
}
You see what I’m trying to mean here right, that the Foo here is a Foo with associated type ‘Key’.
I really want to be able to qualify the Foo with a where clause like
var delegate : Foo where Foo.Key == Key
but you can’t use where clauses like that. Is there a way to write this or is this something which cannot be written.
_______________________________________________
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