且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

【原】Automatic Reference Counting(ARC) properties learning

更新时间:2022-09-15 13:43:33

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.

【原】Automatic Reference Counting(ARC) properties learning
- (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
}
【原】Automatic Reference Counting(ARC) properties learning

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