用@synthesize覆盖Objective-C中的属性访问器名称 [英] Overriding property accessor names in Objective-C with @synthesize

查看:80
本文介绍了用@synthesize覆盖Objective-C中的属性访问器名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试查找有关如何使用@synthesize覆盖Objective-C中的属性名称的文档.如果我有一个实例变量名'foo',我想将它的访问器写为'bar'.

I'm trying to find documentation on how I can override a property name in Objective-C with @synthesize. If I have an instance variable name of 'foo', I want to write it's accessor as 'bar'.

做类似的事情

@synthesize foo = bar;

给出了编译时错误.

推荐答案

您可以但"bar"必须首先存在(作为声明的变量).从文档

You can but "bar" has to exist first (be a declared variable). From the documentation

您可以使用property = ivar的形式表示该属性应使用特定的实例变量,例如:

You can use the form property=ivar to indicate that a particular instance variable should be used for the property, for example:

@synthesize firstName, lastName, age = yearsOld;

这篇关于用@synthesize覆盖Objective-C中的属性访问器名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆