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/ / ...
随机推荐
- k8s Helm安装Prometheus Operator
Ubuntu 18 Kubernetes集群的安装和部署 以及Helm的安装完成了k8s的集群和helm的安装,今天我们来看看Prometheus的监控怎么搞.Prometheus Operator ...
- .NET Core解析DNS域名或主机名的方法
在.NET Core中我们可以用System.Net.Dns类来解析域名或主机名的IP地址,我们新建一个.NET Core控制台项目,写入下面代码: using System; using Syste ...
- Vue传递方法给页面调用
很多人在使用vue的时候苦于在vue中写方法,但是在外部甚至在另一个js该如何调用呢? 这个方法就是显示了vue的可以传递方法到页面使得页面任何地方都可以调用 前提得引用文件 这个方法一般多用于加载周 ...
- Entity Framework 学习系列(1) - 认识理解Entity Framework
目录 写在前面 什么是Entity Framework EF的优缺点 1.优点 2.缺点 如何理解ORM EF执行的原理 写在前面 在使用.net mvc 开发的时候.为了高效的开发,我们常常会搭配O ...
- C++之拷贝控制 (Copy Control)
只有2种成员 值成员: 指针成员: 依实现可分为raw pointer / shared_ptr; 现在,仅考虑第③种:资源对象共享 角度来考虑拷贝控制 类的两种语义:值语义.似指针 编译器提供的de ...
- Spring MVC 复习
概念 三层架构 将整个业务应用划分为三层 表现层:用来和客户端进行数据交互,一般采用MVC设计模式 业务层:处理公司具体业务逻辑 持久层:用来操作数据库 MVC模型 Model View ...
- React Hooks --- useState 和 useEffect
首先要说的一点是React Hooks 都是函数,使用React Hooks,就是调用函数,只不过不同的Hooks(函数)有不同的功能而已.其次,React Hooks只能在函数组件中使用,函数组件也 ...
- vue使用vue-cli创建项目
安装运行环境(node和npm) 安装vue-cli(查看是否安装成功vue -V) 安装webpack 新建项目 1.vue init webpack 项目名称 2.配置项目有关的信息(项目名称,开 ...
- vue+element-ui上传图片时压缩大小
第一种方法:需要安装一个模块 yarn add image-conversion --save <el-upload ref="upload" :data="dat ...
- 医疗行业预测性产品的质量如何把关?MES系统帮大忙
作为行业细分的医疗设备制造正在向工业4.0快速发展.它也可能仍然是世界上受监管最严格的行业之一,产品的个性化发展速度比其他行业更快. 在医疗设备行业中,由于需求或由于市场特定的规定,产品越来越多地定制 ...