Hi,
I'm trying to achieve something like the following:
Concrete class:
class MyClass<Object: AnyObject> : NSObject, MyProtocol {
// [...]
func doSomethingForObject(obj: Object) -> Int {
// [...]
}
// [...]
weak var delegate: MyClassDelegate?
private var updates: [Update<Object>] = []
}
This class conforms to the protocol MyProtocol:
protocol MyProtocol: class {
typealias Object
// [...]
func doSomethingForObject(obj: Object) -> Int
// [...]
}
Here is the delegate protocol:
protocol MyClassDelegate: class {
typealias Object
typealias AClass: MyProtocol
func myClass(myClass: AClass, didUpdate updates: [Update<Object>]?)
}
I've tried different methods to approach this result but I eventually always get one of the following error:
- Protocol MyProtocol / MyClassDelegate can only be used as a generic constraint because it has Self or associated type requirements.
- Cannot invoke 'myClass' with an argument list of type '(MyClass<Delegate>, didUpdate: [Update]?)'
- Circular type reference error
Is it a current limitation of Swift or is there some other way to achieve a similar result ?
Thanks.