The protocol is a type, so you can use it as the declared type of a variable. To use weak
, you must wrap this type as optional. So you would say:
weak var delegate : MyDelegate?
But for this to work, MyDelegate must be a protocol @objc
or class
to ensure that the adopter is a class (and not a struct or enum, as they cannot be weak
).
source
to share