【原】Automatic Reference Counting(ARC) properties learning

简介:

1、With ARC, you should use strong instead of retain and weak instead of assign  when defining the properties.

@interface  Person : NSObject
@property  ( nonatomic , strong) NSString  *firstName;
@property  ( nonatomic , strong) NSString  *lastName;
@property  ( nonatomic , strong) NSNumber  *yearOfBirth;
@property  ( nonatomic , strong) Person *spouse;
@end

2、ARC forbids 'dealloc','release','autorelease' key words, these words shouldn`t be explicitly invoked!

For instance,[super dealloc] [str release] are not permitted.

3、When you use [[AClass alloc] init], you don`t need to release it.

复制代码
- (void)takeLastNameFrom:(Person *)person {

    NSString *oldLastname = [self lastName];

    [self setLastName:[person lastName]];

    NSLog(@"Lastname changed from %@ to %@", oldLastname, [self lastName]);
//oldLastname will stay alive until NSLog is runned
}
复制代码

本文转自编程小翁博客园博客,原文链接:http://www.cnblogs.com/wengzilin/archive/2012/05/04/2482648.html,如需转载请自行联系原作者

相关文章
|
3月前
|
机器学习/深度学习 算法
【文献学习】Channel Estimation Method Based on Transformer in High Dynamic Environment
一种基于CNN和Transformer的信道估计方法,用于在高度动态环境中跟踪信道变化特征,并通过实验结果展示了其相比传统方法的性能提升。
58 0
PAT (Advanced Level) Practice - 1049 Counting Ones(30 分)
PAT (Advanced Level) Practice - 1049 Counting Ones(30 分)
119 0
PAT (Advanced Level) Practice - 1004 Counting Leaves(30 分)
PAT (Advanced Level) Practice - 1004 Counting Leaves(30 分)
109 0
论文笔记:Parallel Tracking and Verifying: A Framework for Real-Time and High Accuracy Visual Tracking
Parallel Tracking and Verifying: A Framework for Real-Time and High Accuracy Visual Tracking    本文目标在于 tracking performance 和 efficiency 之间达到一种平衡。
|
缓存 Java