@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的更多相关文章

  1. ARC声明属性关键字详解(strong,weak,unsafe_unretained,copy)

    ARC声明属性关键字详解(strong,weak,unsafe_unretained,copy) 在iOS开发过程中,属性的定义往往与retain, assign, copy有关,我想大家都很熟悉了, ...

  2. 关于@property()的那些属性及ARC简介【nonatomic,atomic,assign,retain,strong,weak,copy。】

    @property()常用的属性有:nonatomic,atomic,assign,retain,strong,weak,copy. 其中atomic和nonatomic用来决定编译器生成的gette ...

  3. iOS中属性 (nonatomic, copy, strong, weak)的使用 By hL

    以下内容来自Stackflow的详解 1.Nonatomicnonatomic is used for multi threading purposes. If we have set the non ...

  4. ios OC 关键字 copy,strong,weak,assign的区别

    一.先介绍 copy.strong.weak 的区别,如代码所示 @property(copy,nonatomic)NSMutableString*aCopyMStr; @property(stron ...

  5. IOS开发copy,nonatomic, retain,weak,strong用法

     readwrite 是可读可写特性;需要生成getter方法和setter方法时  readonly 是只读特性 只会生成getter方法 不会生成setter方法 ;不希望属性在类外改变  ass ...

  6. iOS Property 关键字的使用

    atomic和nonatomic用来决定编译器生成的getter和setter是否为原子操作.         atomic 设置成员变量的@property属性时,默认为atomic,提供多线程安全 ...

  7. iOS 9 关键字的简单使用

    前言: 在iOS 9 苹果推出了很多关键字, 目的其实很明确, 主要就是提高开发人员的效率, 有益于程序员之间的沟通与交流, 在开发中代码更加规范! 1. nullable 与 nonnull nul ...

  8. Objective-C 关键字:retain, assgin, copy, readonly,atomic,nonatomic

    声明式属性的使用:声明式属性叫编译期语法 @property(retain,nonatomic)Some *s; @property(参数一,参数二)Some *s; 参数1:retain:修饰引用( ...

  9. ios中的关键词retain release

    内存分析  在函数中只要用new  alloc  copy  这样的分配空间时 则计算器retain就要为一 每调用一次就要加一 在.m文件中引用手动计数时 一定要调用[super dealloc]这 ...

随机推荐

  1. MySQL优化-》执行计划和常见索引

    MySql的explain执行计划 explain是一个Mysql性能显示的工具,它显示了MySQL如何使用索引来处理select语句以及连接表.可以帮助选择更好的索引和写出更优化的查询语句.在开发当 ...

  2. 2、ABPZero系列教程之拼多多卖家工具 更改数据库为Mysql

    因为要部署项目到云服务器,不想在服务器上装SqlServer,所以需要把项目改为Mysql. 项目初始化 1.下载项目压缩包,前面文章已经说到,可以加群到群文件里下载.解压缩下载的项目源码,使用VS2 ...

  3. mysql 半同步复制 插件安装以及测试

    mysql Server version:         5.5.18-log MySQL Community Server (GPL)   1.安装插件 检查mysql是否支持动态添加插件: ro ...

  4. [转载]常见slave 延迟原因以及解决方法

    一  序言在运维线上M-M 架构的MySQL数据库时,接收的比较多关于主备延时的报警: 点击(此处)折叠或打开 check_ins_slave_lag (err_cnt:1)critical-slav ...

  5. WPF 依赖属性源码 洞察微软如何实现DependencyProperty

    依赖属性DependencyProperty是wpf最重要的一个类,理解该类如何实现对学习wpf帮助很大! 终于找到了该类的源码!仔细阅读源码,看看微软如何玩的花招! File: Base\Syste ...

  6. Ajax方式分页加载列表实现

    在前面: 最近需要用到这个功能,所以这几天一直在研究这个,目前大致功能已实现,后续需要完善,但需要的功能点已完成,记录下: 1.分页功能引入bootstrap的分页插件: <script typ ...

  7. LoadRunner 中实现MD5加密

    最近在用loadrunner做一个压力测试,在编写脚本的时候发现传递参数的时候需要一个sign值,这个值是将参数进行MD5加密生成的,所以下面就说一说怎么对参数进行MD5加密. 1.首先我们需要一个加 ...

  8. CSS3对于盒中容纳不下的内容的显示——overflow属性

    overflow属性 1.如果将overflow属性值设定为hidden,则超出容纳范围的文字将被隐藏起来. div{ overflow:hidden; } 2.如果将overflow属性值设定为sc ...

  9. 图的简单应用(C/C++实现)

    存档: #include <stdio.h> #include <stdlib.h> #define maxv 10//定义最大顶点数 typedef char elem;// ...

  10. 洛谷 P1055 ISBN号码【字符串+模拟】

    P1055 ISBN号码 题目描述 每一本正式出版的图书都有一个ISBN号码与之对应,ISBN码包括9位数字.1位识别码和3位分隔符,其规定格式如“x-xxx-xxxxx-x”,其中符号“-”就是分隔 ...