I would like to define a protocol which is used in a Viper architecture to establish a connection between a Viper components using a protocol with a weak property but I get the following error message:
'weak' may only be applied to class and class-bound protocol types, not 'Self.ViperViewClass'
protocol ViperPresenter: class {
associatedtype ViperViewClass
weak var view: ViperViewClass! { get set }
}
Protocols can't currently require properties to be implemented as
weak
stored properties.Although the
weak
andunowned
keywords are currently allowed on property requirements, they have no effect. The following is perfectly legal:This was filed as a bug, and SE-0186 will make the use of
weak
andunowned
on property requirements in a protocol a warning in Swift 4.1 (in both Swift 3 and 4 modes), and an error in Swift 5.But even if protocols could require properties to be implemented as
weak
orunowned
stored properties, the compiler would need to know thatViperViewClass
is a class type (i.e by sayingassociatedtype ViperViewClass : AnyObject
).