您的位置:首页 > 其它

基本的ARC使用规则

2015-11-25 12:28 441 查看
代码中不能使用retain, release, retain, autorelease
不重载dealloc(如果是释放对象内存以外的处理,是可以重载该函数的,但是不能调用[super dealloc])
不能使用NSAllocateObject, NSDeallocateObject
不能在C结构体中使用对象指针
id与void *间的如果cast时需要用特定的方法(__bridge关键字)
不能使用NSAutoReleasePool、而需要@autoreleasepool块
不能使用“new”开始的属性名称 (如果使用会有下面的编译错误”Property’s synthesized getter follows Cocoa naming convention for returning ‘owned’ objects”)
----
ARC之@property
属性值
关键字
所有权
strong
__strong

weak
__weak

unsafe_unretained
__unsafe_unretained

copy
__strong

assign
__unsafe_unretained

retain
__strong

1,weak:delegate和IBOutlet用该属性来声明
2,assign:一般数据变量,BOOL
3,unsafe_unretained等价weak。
4,readwrite和readonly-----需要类似@property (nonatomic, strong, readonly) NSString *name;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: