美文网首页
iOS同时重写getter和setter方法时报错问题

iOS同时重写getter和setter方法时报错问题

作者: 小米咸鱼 | 来源:发表于2018-09-14 13:26 被阅读12次

在开发过程中有时需要重新getter、setter方法,很少同时重写这两个方法。今天就同时重写了这两个方法,结果悲剧了,提示找不到Use of undeclared identifier '_supported';did you mean '_supported'。仔细查看了h文件,属性存在也没有写错呀。

解决方法:
在实现中添加

@synthesize supported = _supported;

问题:
同时重写了getter、setter方法会使@property定义的属性无法自动生成私有的成员变量。通过@synthesize设置属性别名;或者手动定义私有成员变量,然后作用到getter、setter方法中。

  注意*协议中声明的属性不会自动生成getter、setter方法,需要@synthesize自动合成getter、setter方法。

相关文章

网友评论

      本文标题:iOS同时重写getter和setter方法时报错问题

      本文链接:https://www.haomeiwen.com/subject/xdlogftx.html