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]这 ...
随机推荐
- 简易排水简车的制作 TurnipBit 系列教程
准备工作 ü TurnipBit 开发板 1块 ü 下载数据线 1条 ü 微型步进电机(28BYJ-48) 1个 ü 步进电机驱动板(ULN2003APG) 1块 ü TurnipBit 扩展板 ...
- js 数组API之forEach、map的用法
forEach语法: arr.forEach(function(value, index, array){--}) 实例: // forEach ,,,,]; arr.forEach(function ...
- input 光标在 chrome下不兼容 解决方案
input 光标在 chrome下不兼容 解决方案 height: 52px; line-height: normal; line-height:52px\9 .list li input[type= ...
- jdk8新特性(文章推荐)
文章推荐 jdk9都已经出来了,虽然很多项目都已经使用jdk8,但是很少会用到jdk8中的新特性.本人经常用的到也就是使用Stream,Lambda,但也仅仅是使用,基本不知道什么Function,C ...
- c/c++ 贪吃蛇控制台版
贪吃蛇控制台版(操作系统win7 64位:编译环境gcc, vs2017通过,其它环境未测试 不保证一定通过) 运行效果: #include <iomanip> #include < ...
- js中的稀疏数组和密集数组
原文地址: http://www.2ality.com/2012/06/dense-arrays.html 一般来说JavaScript中的数组都是稀疏的,也就是说数组中的元素与元素之间是由空格的,因 ...
- Sampling
本文主要涉及接受拒绝采样,重要性采样,蒙特卡洛方法,吉布斯采样等内容.部分内容整理与互联网.仅供交流学习使用!
- 数塔~~dp学习_1
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2084 数塔 Time Limit: 1000/1000 MS (Java/Others) Mem ...
- A * B Problem Plus(fft)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1402 hdu_1402:A * B Problem Plus Time Limit: 2000/100 ...
- 连连看(dfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1175 连连看 Time Limit: 20000/10000 MS (Java/Others) ...