I found out that if I created such a protocol:
protocol MyProtocol { }
I can not do it:
weak var myVar: MyProtocol?
And I found a way to fix this by adding @objcto the protocol declaration:
@objc protocol MyProtocol { }
But why can this fix the error?
I assume that adding @objcprevents the structures from matching for the protocol, so the value of the gurranteed variable is a reference type. I'm right?
In addition, adding @objcdoes not allow me to add fast types such as [String: Any]. I would also like to know if there is another way to fix the error.
source
share