Swift property override not working

前端 未结 2 1021
挽巷
挽巷 2021-02-07 02:11

When I try to override a property I get an error \"can not override mutable property with read-only property\"

I have provided get and set in the super class.

         


        
2条回答
  •  猫巷女王i
    2021-02-07 02:43

    The compiler error message is fairly straightforward: Card's contents property is mutable, which is to say it has a set method in addition to the get method.

    Your override only adds a get method, you need to add a set method too.

    I think this is what you want:

    set(newValue) {
        rankStrings[Int(self.rank)] = newValue;
    }
    

提交回复
热议问题