IOS @proporty 关键字(一)retain strong
@interface User : NSObject @property (nonatomic,retain) NSString* tRetain;
@property (nonatomic,assign) NSString* tAssign;
@property (nonatomic,copy) NSString* tcopy; @end
类User有个属性tRetain, 只是测试就用NSString类型了(此类型一般用copy, 因为可能是个NSMutableString,不希望在赋值后被其他地方修改内容)。
User* user = [[User alloc]init]; NSString* testRetain = [NSString stringWithFormat:@"retain"];
NSLog(@"testRetain.retainCount=%lu",(unsigned long)testRetain.retainCount); //1 user.tRetain = testRetain;
NSLog(@"testRetain.retainCount=%lu",(unsigned long)testRetain.retainCount); //2
NSLog(@"user.tRetain.retainCount=%lu",(unsigned long)user.tRetain.retainCount); //2 NSString* testRetain2 = @"retain2";
NSLog(@"testRetain2.retainCount=%lu",(unsigned long)testRetain2.retainCount); //4294967295 自动释放对象 返回max unsigned long user.tRetain = testRetain2;
NSLog(@"testRetain.retainCount=%lu",(unsigned long)testRetain.retainCount); //1
NSLog(@"testRetain2.retainCount=%lu",(unsigned long)testRetain2.retainCount); //4294967295
NSLog(@"user.RetainValue.retainCount=%lu",(unsigned long)user.tRetain.retainCount); //4294967295 NSString* testRetain3 = [NSString stringWithFormat: @"retain3"];
NSLog(@"testRetain3.retainCount=%lu",(unsigned long)testRetain3.retainCount); //1 [testRetain3 retain];
NSLog(@"testRetain3.retainCount=%lu",(unsigned long)testRetain3.retainCount); //2 NSString* testRetain4 = [NSString stringWithString:testRetain3];
NSLog(@"testRetain3.retainCount=%lu",(unsigned long)testRetain3.retainCount); //3
NSLog(@"testRetain4.retainCount=%lu",(unsigned long)testRetain4.retainCount); //3
strong是ARC后引入的关键字, 在ARC环境中等同于Retain。
NSSring* str = [NSString stringWithString:字符串]; 此方法相当于上文对一个retain属性赋值。 若后面的字符串参数的计数为4294967295,则str的计数也是。 若字符串参数可计数, 例如1, 则执行后计数加1.
IOS @proporty 关键字(一)retain strong的更多相关文章
- ARC声明属性关键字详解(strong,weak,unsafe_unretained,copy)
ARC声明属性关键字详解(strong,weak,unsafe_unretained,copy) 在iOS开发过程中,属性的定义往往与retain, assign, copy有关,我想大家都很熟悉了, ...
- 关于@property()的那些属性及ARC简介【nonatomic,atomic,assign,retain,strong,weak,copy。】
@property()常用的属性有:nonatomic,atomic,assign,retain,strong,weak,copy. 其中atomic和nonatomic用来决定编译器生成的gette ...
- iOS中属性 (nonatomic, copy, strong, weak)的使用 By hL
以下内容来自Stackflow的详解 1.Nonatomicnonatomic is used for multi threading purposes. If we have set the non ...
- ios OC 关键字 copy,strong,weak,assign的区别
一.先介绍 copy.strong.weak 的区别,如代码所示 @property(copy,nonatomic)NSMutableString*aCopyMStr; @property(stron ...
- IOS开发copy,nonatomic, retain,weak,strong用法
readwrite 是可读可写特性;需要生成getter方法和setter方法时 readonly 是只读特性 只会生成getter方法 不会生成setter方法 ;不希望属性在类外改变 ass ...
- iOS Property 关键字的使用
atomic和nonatomic用来决定编译器生成的getter和setter是否为原子操作. atomic 设置成员变量的@property属性时,默认为atomic,提供多线程安全 ...
- iOS 9 关键字的简单使用
前言: 在iOS 9 苹果推出了很多关键字, 目的其实很明确, 主要就是提高开发人员的效率, 有益于程序员之间的沟通与交流, 在开发中代码更加规范! 1. nullable 与 nonnull nul ...
- Objective-C 关键字:retain, assgin, copy, readonly,atomic,nonatomic
声明式属性的使用:声明式属性叫编译期语法 @property(retain,nonatomic)Some *s; @property(参数一,参数二)Some *s; 参数1:retain:修饰引用( ...
- ios中的关键词retain release
内存分析 在函数中只要用new alloc copy 这样的分配空间时 则计算器retain就要为一 每调用一次就要加一 在.m文件中引用手动计数时 一定要调用[super dealloc]这 ...
随机推荐
- JavaScript 浏览器类型及版本号
项目中偶尔用到判断浏览器类型及相关版本问题,现记录相关代码: function getBrowserVertion(userAgent) { var browserName, browserVersi ...
- Java的迭代和foreach循环
Java的迭代(interation statement) Java的迭代(interation statement) 其实就是循环控制语句while.do-while和for,因为他们会从重复地运行 ...
- Tomcat与SpringMVC结合分析(一)
关键字: Bootsrap,Catalina,Server,Service,Engine,Host,Context,Wrapper,Valve,Pipeline,ContextConfig,Servl ...
- VBox 一款基于vue开发的音乐盒 序章
己基于vue写了一个 Mplayer, github地址:https://github.com/xiangwenhu/MPlaer, 演示地址:http://babydairy2017.cloudap ...
- python3基础(二)
loops循环语句 一 if语句,if语句配合else使用,可以没有else. 单分支if语句 age = input('Age:') password = '67' if age == passwo ...
- Twisted使用和scrapy源码剖析
1.Twisted是用Python实现的基于事件驱动的网络引擎框架. 事件驱动编程是一种编程范式,这里程序的执行流由外部事件来决定.它的特点是包含一个事件循环,当外部事件发生时使用回调机制来触发相应的 ...
- View 动画 Animation 运行原理解析
这次想来梳理一下 View 动画也就是补间动画(ScaleAnimation, AlphaAnimation, TranslationAnimation...)这些动画运行的流程解析.内容并不会去分析 ...
- PostgreSQL查询优化器之grouping_planner
grouping_planner主要做了3个工作: 对集合进行处理 对非SPJ函数进行优化 对SQL查询语句进行物理优化 grouping_planner实现代码如下: static void gro ...
- inline函数不能在for循环中使用的原因
inline函数的作用继承了宏定义的优点,没有了参数压栈,代码生成等一部分操作,并且摒弃了没有检查编译规则的缺点: 另外要注意,内联函数一般只会用在函数内容非常简单的时候,这是因为,内联函数的代码会在 ...
- Keepalived实战(3)
一.环境 如上图所示: keepalived的mater为proxy-master,keepalived的slave为proxy-slave. 要求:当mater出现问题时,主动切换到slave上.这 ...