search

Home  >  Q&A  >  body text

objective-c - @property overrides setter and getter methods

Why can’t I access the _ attribute when I rewrite the getter and setter methods at the same time? How can I rewrite the getter and setter methods at the same time? Please help me!

过去多啦不再A梦过去多啦不再A梦2811 days ago760

reply all(2)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-05-02 09:26:48

    This will indeed prompt an error, you need to add a line:

    @synthesize city = _city;

    reply
    0
  • 漂亮男人

    漂亮男人2017-05-02 09:26:48

    After encapsulation, attributes can only be accessed through the encapsulation method. Change _city to self.city. I don’t know if that’s right

    reply
    0
  • Cancelreply