您的位置:首页 > Web前端

【原】Automatic Reference Counting(ARC) properties learning

2012-05-04 14:17 543 查看
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
}


4、
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: