getter/setter

参考链接

@property (nonatomic, retain) NSNumber *count;

- (NSNumber *)count {
    return _count;
}

- (void)setCount:(NSNumber *)count {
    if (count != _count) {
        id oldValue = _count;
        _count = [count retain];
        [oldValue release];
    }
}

@property (nonatomic, copy) NSNumber *count;

- (NSNumber *)count {
    return _count;
}

- (void)setCount:(NSNumber *)count {
    id oldValue = _count;
    _count = [count copy]; // retains (+1)
    [oldValue release];
}

@property (atomic, retain) NSNumber *count;

- (NSNumber *)count {
    NSNumber *count;
    @synchronized(self) {
        count = [_count retain]; // +1
    }
    return [count autorelease]; // delayed -1
}

- (void)setCount:(NSNumber *)count {
    id oldValue;
    @synchronized(self) {
        oldValue = _count;
        _count = [count retain];
    }
    [oldValue release];
} #### @property (assign) NSNumber *count;

- (NSNumber *)count {
    NSNumber *count;
    @synchronized(self) {
        count = _count;
    }
    return count;
}

- (void)setCount:(NSNumber *)count {
    @synchronized(self) {
        _count = count;
    }
}
最近的文章

小技巧集合

实现协议的继承@protocol protocolName1 方法列表……@end@protocol protocolName2 方法列表……@end@synthesize 关键字@synthesize beginTime;@synthesize表示由编译器来自动实现beginTime的getter/setter方法,不需要你自己再手动去实现。@protocol 关键字@property 主要的作用就在于封装对象中的数据。@property = ivar + getter + setter...…

继续阅读
更早的文章

面试题基础原理

面试时经常被问到的基础👇这个链接的整理比较完整,对一些感觉自己基础比较差又无从下手的我们来说可是一大干货集。特此分享,也提供自己查缺补漏~~~iOS面试基础原理…

allportfoliosomething继续阅读