Class only protocol - why the examples are not working?

This is because mutating means that self can be reassigned, which is not permitted for let constants even of reference type (i.e., classes). Recall that when you modify a struct member, you modify the whole struct, but this is not the case when you modify a class member.

This is a common point of confusion and is discussed at length here and here and here and here.

1 Like