Seeing what I believe is a bug in Swift with a generic based protocol. The protocol is below:
protocol Coordinated {
associatedtype GenericCoordinatingDelegate: CoordinatingDelegate
weak var coordinatingDelegate: GenericCoordinatingDelegate? { get set }
}
protocol CoordinatingDelegate: NSObjectProtocol { }
Xcode shows an error with this, however, claiming that 'weak' may only be applied to class and class-bound protocol types, not Self.GenericCoordinatingDelegate
.
Now, correct me if I'm wrong, but GenericCoordinatingDelegate
is here constrained to the CoordinatingDelegate
protocol type defined below, which is derived from NSObjectProtocol
, hence constraining it to classes only. Swift can see this and therefore should allow the weak
modifier to be used on the property derived from it.
Can anyone see anything that I've missed or is this actually a bug in Swift?
EDIT:
Thank you for your suggestion, Hamish, I have edited my code to reflect this. However, I am now getting another strange issue.
class WelcomeIntroViewController: UIViewController, OnboardingViewController, TwoPartGradientLayerProvider, Coordinated {
typealias GenericCoordinatingDelegate = WelcomeCoordinatingDelegate
weak var coordinatingDelegate: GenericCoordinatingDelegate?
That is the implementation of the protocol as defined above, however, Swift claims that the view controller does not conform to the protocol, and tries to add another typealias
. It will do this continuously, even with like 50 matching typealias
es. Not sure what's going on here?