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]这 ...
随机推荐
- springboot mybatis 事务管理
本文主要讲述springboot提供的声明式的事务管理机制. 一.一些概念 声明式的事务管理是基于AOP的,在springboot中可以通过@Transactional注解的方式获得支持,这种方式的优 ...
- JDBC详解系列(三)之建立连接(DriverManager.getConnection)
在JDBC详解系列(一)之流程中,我将数据库的连接分解成了六个步骤. JDBC流程: 第一步:加载Driver类,注册数据库驱动: 第二步:通过DriverManager,使用url,用户名和密码 ...
- NUnit实战,第一个测试类,测试事件触发是否是并行的
以前测试都是新建一个控制台测试的方式来进行,感觉版本管理啥的非常麻烦.也是非常原始的办法.后来想以前有写过测试单元,不过好久没弄了.Nuget了NUnit后写了正式的第一个测试类. 测试用例: 测试事 ...
- Windows下搭建Redis服务器
Redis服务器是当下比较流行的缓存服务器,Redis通常被人拿来和Memcached进行对比.在我看来,应当是各具优势吧,虽然应用场景基本类似,但总会根据项目的不同来进行不通的选用. 我们今天主要讲 ...
- VMware仅主机模式虚拟机无法ping通物理机
问题描述 在VMware Workstation中新建了一个虚拟机CentOS7,网络适配器选择的是"仅主机模式",结果,物理机ping不通虚拟机,虚拟机也ping不通物理机. 原 ...
- 为 MariaDB 配置远程访问权限
最近在配置MySQL远程连接的时候发现我的MySQL数据库采用的是 MariaDB 引擎,与普通的数据库配置有点不同 经过查找资料终于完成了,特此记录方便以后查询 MariaDB 与普通的MySQL数 ...
- ActiveMQ进阶学习
本文主要讲述ActiveMQ与spring整合的方案.介绍知识点包括spring,jms,activemq基于配置文件模式管理消息,消息监听器类型,消息转换类介绍,spring对JMS事物管理. 1. ...
- 聊聊C#与冲顶大会
一.由跳一跳开始 2018年初,跳一跳小程序着实火了一把.一时间,各种攻略,甚至辅助工具也应运而生.作为.net阵营的一员,园友的这篇http://www.cnblogs.com/bqh10086/p ...
- Mistakes in Hello World
今天在cmd中用Python写第一行代码"Hello World"出现错误. 写好的源码"HelloWorld.py"存放于" F:\learning ...
- Sql的基础知识(一)
一.基础 1.说明:创建数据库 CREATE DATABASE database-name 2.说明:删除数据库 drop database dbname 3.说明:备份 sql server --- ...