1. @interface MyClass : NSObject {
  2. NSString *name;
  3. NSArray *items;
  4.  
  5. Something *something;
  6.  
  7. IBOutlet NSTextField *myTextField;
  8. }
  9.  
  10. @property (nonatomic, retain) NSString *name;
  11. @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:

  1. name =@"Test";

and

  1. 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 released 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的更多相关文章

  1. 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 ...

  2. non-ARC代码转 ARC 排除 “Existing instance variable 'delegate' for property with assign attribute must be _unsafe _unretained” 错误

    原来非ARC代码是 @interface MHWebImageDownloader : NSObject { id<MHWebImageDownloaderDelegate> delega ...

  3. Summary: Class Variable vs. Instance Variable && Class Method

    这里列举的是一些我平时碰到的一些Java Grammar,日积月累. Class Variable vs Instance Variable: Instance variables Instance ...

  4. Swift开发教程--关于Existing instance variable &#39;_delegate&#39;...的解决的方法

    xcode编译提示问题:Existing instance variable '_delegate' for property 'delegate' with  assign attribute mu ...

  5. 警告"Local declaration of 'XXX' hides instance variable"原因

    Local declaration of 'XXX' hides instance variable   是因为本地变量名跟函数变量名同名 ,.在命名上要注意.....  

  6. Local declaration of 'XXX' hides instance variable

    今天调试程序遇到这么一个警告! Local declaration of 'XXX' hides instance variable 遇到这种原因,是因为本地变量跟函数参数变量同名.改变其一即可.

  7. Instance Variable Hiding in Java

    class Test { // Instance variable or member variable private int value = 10; void method() { // This ...

  8. tensorflow共享变量 the difference between tf.Variable() and get_variable()

    一般这样用tf.get_variable(): v = tf.get_variable(name, shape, dtype, initializer) 下面内容来源于 http://blog.csd ...

  9. 虚拟变量和独热编码的区别(Difference of Dummy Variable & One Hot Encoding)

    在<定量变量和定性变量的转换(Transform of Quantitative & Qualitative Variables)>一文中,我们可以看到虚拟变量(Dummy Var ...

随机推荐

  1. Jquery_笔记

    1.请确保在 <body> 元素的onload事件中没有注册函数,否则不会触发+$(document).ready()事件.

  2. pascal矩阵 分类: 数学 2015-07-31 23:01 3人阅读 评论(0) 收藏

    帕斯卡矩阵 1.定义       帕斯卡矩阵:由杨辉三角形表组成的矩阵称为帕斯卡(Pascal)矩阵. 杨辉三角形表是二次项 (x+y)^n 展开后的系数随自然数 n 的增大组成的一个三角形表. 如4 ...

  3. Gym 100285G Cipher Message 3

    题意 给\(N,M(N,M \le 250000)\)的两个由8位二进制表示的两个序列,允许改变每个数字的第8位的数值(即0→1,1→0),求改变最少次数使得长为\(M\)的序列为长为\(N\)的连续 ...

  4. ARM1138@PWM例程分析

    1. Buzzer例程控制原理 由ARM1138原理图可得:Buzzer使用CCP3(对应GPIO-G组0x40026000,4号引脚0x00000010)作为输入引脚: Buzzer例程结构: 涉及 ...

  5. Java——日期格式

     /* * 日期对象和毫秒值之间的转换. * * 毫秒值--->日期对象: *  1.通过Date对象的构造方法new Date(timeMillis) *  2.还可以通过setTime设 ...

  6. python文件操作--字符串替换

    如把test.txt文件的 所有 AAA 字符串 替换成 aaaaa with open('test.txt','+r') as f: t = f.read() t = d.replace('AAA' ...

  7. java打包压缩文件

    package com.it.simple.util; import java.io.BufferedOutputStream;import java.io.ByteArrayOutputStream ...

  8. What are the main disadvantages of Java Server Faces 2.0?

    http://stackoverflow.com/questions/3623911/what-are-the-main-disadvantages-of-java-server-faces-2-0/ ...

  9. CentOS 6.5系统上安装SVN服务器端的方法及步骤

    VN其实就是Subversion,分为服务器端和客户端.之前在网上搜了很多方法,都有各种问题,经过自己搜集整理以及实际尝试,总算有个比较靠谱的方法.本文主要介绍CentOS 6.5系统上安装SVN服务 ...

  10. awk笔记

    http://www.cnblogs.com/zhuyp1015/archive/2012/07/14/2591842.html awk实例练习 http://www.cnblogs.com/repo ...