@interface User : NSObject @property (nonatomic,retain) NSString* tRetain; @property (nonatomic,assign) NSString* tAssign; @property (nonatomic,copy) NSString* tcopy; @end 类User有个属性tRetain, 只是测试就用NSString类型了(此类型一般用copy, 因为可能是个NSMutableString,不希望在赋值后被…
ARC声明属性关键字详解(strong,weak,unsafe_unretained,copy) 在iOS开发过程中,属性的定义往往与retain, assign, copy有关,我想大家都很熟悉了,在此我也不介绍,网上有很多相关文章. 但是在iOS 5中加入ARC,产生了几个新的关键字strong, weak, unsafe_unretained.  我们可以将其与以前的关键字对应学习: strong与retain类似,weak和unsafe_unretained这两个新关键字与assign类…
@property()常用的属性有:nonatomic,atomic,assign,retain,strong,weak,copy. 其中atomic和nonatomic用来决定编译器生成的getter和setter是否为原子操作. NSObject对象的@property属性时,默认为atomic,提供多线程安全. 在多线程环境下,原子操作是必要的,否则有可能引起错误的结果.加了atomic,setter函数会变成下面这样: NSLock *_lock = [[NSLock alloc]ini…
以下内容来自Stackflow的详解 1.Nonatomicnonatomic is used for multi threading purposes. If we have set the nonatomic attribute at the time of declaration, then any other thread wanting access to that object can access it and give results in respect to multi-th…
一.先介绍 copy.strong.weak 的区别,如代码所示 @property(copy,nonatomic)NSMutableString*aCopyMStr; @property(strong,nonatomic)NSMutableString*strongMStr; @property(weak,nonatomic)NSMutableString*weakMStr; @property(assign,nonatomic)NSMutableString*assignMStr; NSMu…
 readwrite 是可读可写特性;需要生成getter方法和setter方法时  readonly 是只读特性 只会生成getter方法 不会生成setter方法 ;不希望属性在类外改变  assign 是赋值特性,setter方法将传入参数赋值给实例变量;仅设置变量时;  retain 表示持有特性,setter方法将传入参数先保留,再赋值,传入参数的retaincount会+1;  copy 表示赋值特性,setter方法将传入对象复制一份;需要完全一份新的变量时.  nonatomic…
atomic和nonatomic用来决定编译器生成的getter和setter是否为原子操作.         atomic 设置成员变量的@property属性时,默认为atomic,提供多线程安全. 在多线程环境下,原子操作是必要的,否则有可能引起错误的结果.加了atomic,setter函数会变成下面这样:                        {lock}                                if (property != newValue) {    …
前言: 在iOS 9 苹果推出了很多关键字, 目的其实很明确, 主要就是提高开发人员的效率, 有益于程序员之间的沟通与交流, 在开发中代码更加规范! 1. nullable 与 nonnull nullable : 表示可以为 nil nonnull : 表示不可以为 nil 这两个关键字只能修饰对象, 不能修饰基本数据类型, 可以用在属性, 方法的参数, 方法的返回值使用, 在默认情况下, 不加nullable, setter 和 getter 都是可以为nil 我们来看下如何使用, 以nul…
声明式属性的使用:声明式属性叫编译期语法 @property(retain,nonatomic)Some *s; @property(参数一,参数二)Some *s; 参数1:retain:修饰引用(对象)数据类型 assgin:修饰基本数据类型(默认) copy:一些对象需要复制才能使用NSString readonly:只读,只有setter方法,没有getter方法 参数2:保证多线程的安全性 atomic:原子性 线程是安全的,但效率低(默认) nonatomic: 非原子性 线程是不安…
内存分析  在函数中只要用new  alloc  copy  这样的分配空间时 则计算器retain就要为一 每调用一次就要加一 在.m文件中引用手动计数时 一定要调用[super dealloc]这里的.m不是main文件  …