点语法和合成
我想知道合成是否对点语法有某种支持。我的目标只是了解更多信息 - 我意识到我可以通过自己定义吸气剂来实现目标。到目前为止,我一直在寻找有关该主题的信息,但没有取得多大成功。
我想做的例子:
@synthesize name = self.someObject.name;
作为一个吸气剂,将是这样的:
-(NSString*)name
{
return self.someObject.name;
}
I was wondering if synthesize has some sort of support for dot syntax. My goal here is just to learn more about it - I realize I can achieve the goal by defining the getter myself. I have been looking for info on this topic without much success so far.
Example of what I want to do:
@synthesize name = self.someObject.name;
Which, as a getter, would be something along the lines of:
-(NSString*)name
{
return self.someObject.name;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,你不能这样做。
@synthesize
中=
后面的值必须引用当前类的 ivar。正如您所指出的,您可以自由地实现上述 getter,但@synthesize
不会这样做。No, you can't do this. The value after the
=
in@synthesize
must reference an ivar of the current class. You're free to implement the above getter as you've noted, but@synthesize
won't do it.