Last active
May 4, 2018 06:18
-
-
Save zhangkn/cd4f098321241830d3d7e1601a9ddd3a to your computer and use it in GitHub Desktop.
atomic:原子属性,为setter方法加锁(默认就是atomic)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// OC在定义属性时有nonatomic和atomic两种选择 | |
1)atomic:原子属性,为setter方法加锁(默认就是atomic) | |
2)nonatomic:非原子属性,不会为setter方法加锁 | |
//一、原子和非原子属性的选择 | |
1、nonatomic和atomic对比 | |
1)atomic:线程安全,需要消耗大量的资源 | |
2)nonatomic:非线程安全,适合内存小的移动设备 | |
//2、 iOS开发的建议 | |
1)所有属性都声明为nonatomic | |
2)尽量避免多线程抢夺同一块资源 | |
3)尽量将加锁、资源抢夺的业务逻辑交给服务 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment