ios中setter和getter的写法
2015-11-09 06:50
435 查看
简单的说一下非原子性的nonatomic实现
atomic实现:
- (void)setCurrentImage:(UIImage *)currentImage { if (_currentImage != currentImage) { [_currentImage release]; //如果是nsstring类型,则是copy _currentImage = [currentImage retain]; // do something } } - (UIImage *)currentImage { if (_currentImage == nil) { _currentImage = [[UIImage alloc]init] ; } return _currentImage; }
atomic实现:
- (void)setCurrentImage:(UIImage *)currentImage { @synchronized(self) { if (_currentImage != currentImage) { [_currentImage release]; _currentImage = [currentImage retain]; // do something } } } - (UIImage *)currentImage { @synchronized(self) { UIImage *image = [_currentImage retain]; return [image autorelease]; } }
相关文章推荐
- xcode iOS 模拟器 textField 鼠标点击后键盘不显示
- ios method swizzling
- ios逆向工程
- iOS 项目的目录结构
- iOS中的RunTime机制
- GCD基础知识
- ios storyboard 按钮圆角
- [IOS]vmxsmc.exe已停止工作 VMware11 Unlocker for Mac OSX无法使用的解决办法.
- iOS 单例模式的介绍和写法
- iOS本地推送(本地通知)
- ios证书 配置文件 沙盒保护 代码签名
- What causes iOS iCloud error: Error Domain=BRCloudDocsErrorDomain Code=12 “The operation couldn’t be
- 蓝懿ios 技术内容和心得交流分享 11.8
- iOS项目中删除默认的并使用自建的ViewController后黑屏
- iOS 状态栏管理
- 文件系统
- #在蓝懿学习iOS的日子#day14
- iOS讲解迷惑--LeanCloud
- iOS:KVO的概述与使用
- iOS讲解迷惑--AFNetworking的使用