@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 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. C#各类型大小

  2. GridView用法大全(转)

    http://www.cnblogs.com/sufei/archive/2010/03/27/1698590.html

  3. 使用Metasploit进行端口扫描

    Metasploit中不仅能够使用第三方扫描器Nmap等,在其辅助模块中也包含了几款内建的端口扫描器. 查看Metasploit框架提供的端口扫描工具: msf > search portsca ...

  4. hdu3342 拓扑序

    题意:一个QQ群里面有一群大神,他们互相帮助解决问题,然后互相膜拜,于是有些人就称别人是他师父,现在给出很多师徒关系,问是否有矛盾 拓扑序,按师徒关系建边直接拓扑序就行了. #include<s ...

  5. java大数

    java大数还是很好用的! 基本加入: import java.math.BigInteger; import jave.math.BigDecimal; 分别是大数和大浮点数. 首先读入可以用: S ...

  6. 【HAOI2009】【P1307】毛毛虫

    感觉相比其他树归题简单多了,不过有点绕(也许是我的思路很奇怪一.一)(这是省选题啊,就算作为T1这题也太水了,HA好弱……) 原题: 对于一棵树,我们可以将某条链和与该链相连的边抽出来,看上去就象成一 ...

  7. breakpoints

    https://blogs.msdn.microsoft.com/visualstudioalm/2013/10/07/breakpoints-in-visual-studio-2013/ Using ...

  8. java 将长度很长的字符串(巨大字符串超过4000字节)插入oracle的clob字段时会报错的解决方案

    直接很长的字符串插入到clob字段中会报字符过长的异常,相信大家都会碰到这种情况 String sql = "insert into table(request_id,table_name, ...

  9. Goal driven performance optimization

    When your goal is to optimize application performance it is very important to understand what goal d ...

  10. easyUI之Combo

    Combo组件为自定义下拉列表组件,无class的加载方式,主要是通过jquery的方式.它依赖于validatebox,可以用它的很多属性.例如: 前台: <div id="box& ...