difference between instance variable and property
@interface MyClass : NSObject {
NSString *name;
NSArray *items; Something *something; IBOutlet NSTextField *myTextField;
} @property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSArray *items;
in the iPhone world, there's no garbage collector available. You'll have to carefully manage memory with reference counting. With that in mind, consider the difference between:
name =@"Test";
and
self.name =@"Test";// which is equivalent to:[self setName:@"Test"];
If you directly set the instance variable, without prior consideration, you'll lose the reference to the previous value and you can't adjust its retain count (you should have release
d it manually). If you access it through a property, it'll be handled automatically for you, along with incrementing the retain count of the newly assigned object.
The fundamental concept is not iPhone specific but it becomes crucial in an environment without the garbage collector.
Declaring ivar via just declaring a property for it is a new language feature available starting objc 2.0
In "Run-time differences" section of "Objective-c programming language" reference stated:
For @synthesize to work in the legacy runtime, you must either provide an instance variable with the same name and compatible type of the property or specify another existing instance variable in the @synthesize statement. With the modern runtime, if you do not provide an instance variable, the compiler adds one (_propertyName) for you.
difference between instance variable and property的更多相关文章
- You Can Customize Synthesized Instance Variable Names @property
As mentioned earlier, the default behavior for a writeable property is to use an instance variable c ...
- non-ARC代码转 ARC 排除 “Existing instance variable 'delegate' for property with assign attribute must be _unsafe _unretained” 错误
原来非ARC代码是 @interface MHWebImageDownloader : NSObject { id<MHWebImageDownloaderDelegate> delega ...
- Summary: Class Variable vs. Instance Variable && Class Method
这里列举的是一些我平时碰到的一些Java Grammar,日积月累. Class Variable vs Instance Variable: Instance variables Instance ...
- 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 遇到这种原因,是因为本地变量跟函数参数变量同名.改变其一即可.
- Instance Variable Hiding in Java
class Test { // Instance variable or member variable private int value = 10; void method() { // This ...
- tensorflow共享变量 the difference between tf.Variable() and get_variable()
一般这样用tf.get_variable(): v = tf.get_variable(name, shape, dtype, initializer) 下面内容来源于 http://blog.csd ...
- 虚拟变量和独热编码的区别(Difference of Dummy Variable & One Hot Encoding)
在<定量变量和定性变量的转换(Transform of Quantitative & Qualitative Variables)>一文中,我们可以看到虚拟变量(Dummy Var ...
随机推荐
- Jquery判断滚动条是否到达窗口顶部和底部
<script type="text/javascript"> $(document).ready(function(){ alert($(window).he ...
- 不容易系列之(3)—— LELE的RPG难题
有排成一行的n个方格,用红(Red).粉(Pink).绿(Green)三色涂每个格子,每格涂一色,要求任何相邻的方格不能同色,且首尾两格也不同色.求全部的满足要求的涂法. 思路:运用递归算法. a[1 ...
- HDU 2096 小明A+B --- 水题
HDU 2096 /* HDU 2096 小明A+B --- 水题 */ #include <cstdio> int main() { #ifdef _LOCAL freopen(&quo ...
- 黑马程序员——JAVA基础之数组
------- android培训.java培训.期待与您交流! ---------- 数组: 数组的定义: 数组是相同类型数据的集合, 描述的是相同类型的若干个数据按照一定的先后顺序排列组合而成,其 ...
- The EM Algorithm
EM是我一直想深入学习的算法之一,第一次听说是在NLP课中的HMM那一节,为了解决HMM的参数估计问题,使用了EM算法.在之后的MT中的词对齐中也用到了.在Mitchell的书中也提到EM可以用于贝叶 ...
- mysql学习之-密码管理(默认密码,修改密码,解决忘记密码)
1. mysql安装后默认没有密码,初始化安装后默认密码登录,需要马上修改root密码.[root@mysql ~]# cat /root/.mysql_secret --查看root账号密码# ...
- 转(JSONP处理跨域事件)
前言: 由于Sencha Touch 2这种开发模式的特性,基本决定了它原生的数据交互行为几乎只能通过AJAX来实现. 当然了,通过调用强大的PhoneGap插件然后打包,你可以实现100%的Soc ...
- HTML和JSON的数据交互-jsonp跨域
HTML和json的数据交互 <!DOCTYPE html> <html> <head> <script src="//ajax.googleapi ...
- SQL Server 备份故障
故障信息如下: 标题: Microsoft SQL Server Management Studio------------------------------备份 对于 服务器“*******”失败 ...
- Windows Azure 生成证书
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64>makecert -sky exchange -r -n &qu ...