property的讲解

Code
Meaning

R
The property is read-only (readonly).

C
The property is a copy of the value last assigned (copy).

&
The property is a reference to the value last assigned (retain).

N
The property is non-atomic (nonatomic).

G<name>
The property defines a custom getter selector name. The name follows the G (for example, GcustomGetter,).

S<name>
The property defines a custom setter selector name. The name follows the S (for example, ScustomSetter:,).

D
The property is dynamic (@dynamic).

W
The property is a weak reference (__weak).

P
The property is eligible for garbage collection.

t<encoding>
Specifies the type using old-style encoding.


一个个说 先说 
nonatomic 
系统默认 是 atomic的 你不声明就意味着是 atomic 效果是,在多线程操作的时候
假如多个线程都会用到这个变量,那么你在读写这个变量的时候 会有一个 lock 和unlock的操作 防止在读写的过程中,变量被其他的线程所改变,导致错误.
像下面这样
[_internal lock]; // lock using an object-level lock 
id result = [[value retain] autorelease]; 
[_internal unlock]; 
return result;



如果你声明了 nonatomic ,你确认这个变量不会在多线程中用到的话,那么 读写只是简单的返回 没有 lock的动作 效率上就提高了


通常说nonatomic 是提高在非多线程应用中的 读写效率 

readwrite 和 readonly 是一起说的.在不声明的时候 默认是带readwrite参数的 就是 这个变量可以读写.
如果你声明了readonly 就是只读 

assign retain 和copy 要一起说

copy 是创建分配一个新的空间,从原址的内容复制内容过来.

assign 只是简单的传递指针.

retain 是在传递指针后 retainCount +1

dealloc 后relase的事情,建议是在每个 object的 m文件里 成对的创建和销毁变量.谁创建,谁负责销毁,谁retain 谁来release

posted on 2011-01-12 13:30  wwwkhd  阅读(536)  评论(0编辑  收藏  举报