I have a class with a delegate. I am creating a subclass that also has a delegate. I wanted the protocol used for the second delegate to extend the protocol used for the first delegate:
protocol MySuperClassProtocol { func foo() } class MySuperClass { var delegate:MySuperClassProtocol? } protocol MySubClassProtocol:MySuperClassProtocol { func bar() } class MySubClass: MySuperClass { override var delegate:MySubClassProtocol?
Is there any way to solve this? The only possible solution that I see is to make the 2 protocols independent of each other and use different names. Like this:
protocol MySuperClassProtocol { func foo() } class MySuperClass { var mySuperClassDelegate:MySuperClassProtocol? } protocol MySubClassProtocol { func bar() } class MySubClass: MySuperClass { var mySubClassDelegate:MySubClassProtocol? func test() { mySuperClassDelegate?.foo() mySubClassDelegate?.bar() } } class UserClass:MySuperClassProtocol, MySubClassProtocol { func foo() { println("foo!") } func bar() { println("bar") } }
But it looks a little strange + will not allow me to use the delegate naming convention - "delegate".
ios swift
Ix
source share