When using the delegate pattern to communicate between classes, standard practice is to do the following:
- Create a protocol to define the delegate
- Define a weak var of the protocol type
Doing only these steps will yield the following error:
"'weak' must not be applied to non-class-bound 'FooDelegate'; consider adding a protocol conformance that has a class bound"
A quick fix is to add a class declaration to your protocol. Meaning change this:
protocol FooDelegate {}
To this:
protocol FooDelegate: class {}
That’s all you need!