Class bound protocol conformance

When using the delegate pattern to communicate between classes, standard practice is to do the following:

  1. Create a protocol to define the delegate
  2. 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!

Leave a Reply

Your email address will not be published. Required fields are marked *