Cannot assign to property in protocol – Swift compiler error

@matt’s anwer is correct.

Another solution is to declare Nameable as a class only protocol.

protocol Nameable: class {
//               ^^^^^^^ 
    var name : String { get set }
}

I think, this solution is more suitable for this case. Because nameNameable is useless unless nameable is a instance of class.

Leave a Comment