MRC:
@interface People : NSObject
@property (nonatomic,retain) NSArray *oneArr;
@end
setter:
- (void)setOneArr:(NSArray *)oneArr{
if (_oneArr != oneArr) {
[oneArr release];
_oneArr = [oneArr retain];//或者copy视情况而定
}
}
getter:
- (NSArray *)oneArr{
if (!_oneArr) {
_oneArr = @[@"1",@"2",@"3"];
}
return [[_oneArr retain] autorelease];
}
ARC:
@interface People : NSObject
@property (nonatomic,strong) NSArray *twoArr;
@end
setter:
- (void)setTwoArr:(NSArray *)twoArr{
if (_twoArr != twoArr) {
_twoArr = twoArr;
}
}
getter:
- (NSArray *)twoArr{
if (!_twoArr) {
self.twoArr = @[@"1",@"2",@"3"];
}
return _twoArr;
}