You Can Customize Synthesized Instance Variable Names @property
As mentioned earlier, the default behavior for a writeable property is to use an instance variable called _propertyName.
If you wish to use a different name for the instance variable, you need to direct the compiler to synthesize the variable using the following syntax in your implementation:
@implementation YourClass |
@synthesize propertyName = instanceVariableName; |
... |
@end |
For example:
@synthesize firstName = ivar_firstName; |
In this case, the property will still be called firstName, and be accessible through firstName and setFirstName: accessor methods or dot syntax, but it will be backed by an instance variable called ivar_firstName.
Important: If you use @synthesize without specifying an instance variable name, like this:
@synthesize firstName; |
the instance variable will bear the same name as the property.
In this example, the instance variable will also be called firstName, without an underscore.
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/EncapsulatingData/EncapsulatingData.html#//apple_ref/doc/uid/TP40011210-CH5-SW2
You Can Customize Synthesized Instance Variable Names @property的更多相关文章
- difference between instance variable and property
@interface MyClass : NSObject { NSString *name; NSArray *items; Something *something; IBOutlet NSTex ...
- non-ARC代码转 ARC 排除 “Existing instance variable 'delegate' for property with assign attribute must be _unsafe _unretained” 错误
原来非ARC代码是 @interface MHWebImageDownloader : NSObject { id<MHWebImageDownloaderDelegate> delega ...
- Swift开发教程--关于Existing instance variable '_delegate'...的解决的方法
xcode编译提示问题:Existing instance variable '_delegate' for property 'delegate' with assign attribute mu ...
- 警告"Local declaration of 'XXX' hides instance variable"原因
Local declaration of 'XXX' hides instance variable 是因为本地变量名跟函数变量名同名 ,.在命名上要注意.....
- Local declaration of 'XXX' hides instance variable
今天调试程序遇到这么一个警告! Local declaration of 'XXX' hides instance variable 遇到这种原因,是因为本地变量跟函数参数变量同名.改变其一即可.
- Summary: Class Variable vs. Instance Variable && Class Method
这里列举的是一些我平时碰到的一些Java Grammar,日积月累. Class Variable vs Instance Variable: Instance variables Instance ...
- Instance Variable Hiding in Java
class Test { // Instance variable or member variable private int value = 10; void method() { // This ...
- IOS Intro - Property Synthesis
http://www.thecodecrate.com/ios/objective-c/objective-c-property-synthesize/ 01. atomic ...
- 李洪强iOS经典面试题上
李洪强iOS经典面试题上 1. 风格纠错题 修改完的代码: 修改方法有很多种,现给出一种做示例: // .h文件 // http://weibo.com/luohanchenyilong/ / ...
随机推荐
- 笔记:Map(就是用来Ctrl+C,V的)
JDK1.8:List -> Map: 1,Map<String, String> maps = userList.stream().collect(Collectors.toMap ...
- Python3注解+可变参数实现
一.说明 1.1 关于注解 关于注解这个东西,最早是在大学学java的时候经常会看到某些方法上边@override之类的东西,一方面不知道其作用但另一方面似乎去掉也没什么影响,所以一直都不怎么在意. ...
- Win10 系统直接在目录下打开cmd
每次用cmd命令,就要定位到当前文件夹,很麻烦 这里介绍一种直接定位到要操作的文件夹的方法: 操作步骤: (1)选择要cmd的文件夹,按住Shift键,鼠标右键快捷方式,先打开Powershell窗口 ...
- AntDesign vue学习笔记(四)使用组件切换
同样实现上一篇功能, 改为使用组件切换,实现方法如下 1.修改MainFrm中的<router-view/>如下代码 2.注册局部组件 export default { name: 'Ma ...
- C++指针与数组、函数、动态内存分配
C++指针 指针是用来存储地址的变量. 对于二维数组来说: a:代表的是首行地址: *a:代表的是首元素地址: **a:首元素: a+1:第二行地址: *a+2:首先*a是首元素地址,在首元素地址上+ ...
- HyperFT项目安卓端的环境搭建及编译的图解教程
一.Android studio 3.5安装详解 1.安装IDE 安装前的准备:已安装过的需要卸载,并且删除C:\user\yourname\ 下.android ,gradle, .AndroidS ...
- 利用Travis IC实现Hexo博客自动化部署
1.Hexo博客的利与弊 Hexo中文 我就默认为看到这篇文章的人都比较了解Hexo博客,也都能够成功手动部署吧.所以第一部分推荐两篇文章一笔带过,让我们快速进入本文的重点内容.实在不知道也不要方先看 ...
- React 根据条件自动计算
1.输入框 <Item {...formItemProps} label="留房日期"> {getFieldDecorator('date', { rules: [{ ...
- Orleans 3.0 为我们带来了什么(转载)
以下为本篇文章的 作者: 艾心 出处: https://www.cnblogs.com/edison0621/ 原文:https://devblogs.microsoft.com/dotnet/orl ...
- C#读写设置修改调整UVC摄像头画面-对比度
有时,我们需要在C#代码中对摄像头的对比度进行读和写,并立即生效.如何实现呢? 建立基于SharpCamera的项目 首先,请根据之前的一篇博文 点击这里 中的说明,建立基于SharpCamera的摄 ...