Property attributes
There are many attributes for property as follows:
- atomic:
- Is default behavior
- will ensure the present process is completed by the cpu, before another process access the variable
- not fast, as it ensures the process is completed entirely
- nonatomic:
- Is NOT default behavior
- faster (for synthesized code, ie for variable created using @property, @synthesize )
- not thread safe
- may result in unexpected behavior, when two different process access the same variable at the same time
- copy: is required when the object is mutable. Use this if you need the value of the object as it is at this moment, and you don't want
that value to reflect any changes made by other owners of the object. You will need to release the object when you are finished with it because you are retaining the copy. For attributes whose
type is an immutable value class that conforms to theNSCopying
protocol,
you almost always should specifycopy
in
your@property
declaration.
- retain: is
required when the attribute is a pointer to an object. The setter generated by@synthesize
will
retain (aka add a retain count to) the object. You will need to release the object when you are finished with it. By using retain it will increase the retain count and occupy memory in autorelease pool.
- strong: is a replacement for the retain attribute, as part of Objective-C Automated Reference Counting (ARC). In non-ARC
code it's just a synonym for retain.
- weak: is similar to
strong
except
that it won't increase the reference count by 1. It does not become an owner of that object but just holds a reference to it. If the object's reference count drops to 0, even though you may still be pointing to it here, it will be deallocated from memory.
- assign: is
somewhat the opposite tocopy
.
When calling the getter of anassign
property,
it returns a reference to the actual data. Typically you use this attribute when you have a property of primitive type (float, int, BOOL...)
A reference: http://www.raywenderlich.com/5677/beginning-arc-in-ios-5-part-1
Property attributes的更多相关文章
- @property语句
@property声明的形式是: @property ( attributes ) type name; type和name的含义一目了然,attributes描述了如何编写访问器. 一.assign ...
- Unity属性(Attributes)
Unity3d中的属性(Attributes) Attributes属性属于U3D的RunTimeClass,所以加上以下的命名空间是必须的了. using UnityEngine; using Sy ...
- QML Object Attributes QML对象属性
QML Object Attributes Every QML object type has a defined set of attributes. Each instance of an obj ...
- iOS @property语句
@property声明的形式是: @property ( attributes ) type name; type和name的含义一目了然,attributes描述了如何编写访问器. 一.assign ...
- iOS runtime探究(三): 从runtime開始理解OC的属性property
你要知道的runtime都在这里 转载请注明出处 http://blog.csdn.net/u014205968/article/details/67639303 本文主要解说runtime相关知识, ...
- [翻译]NUnit---Property and Random Attributes(十四)
小记:由于工作琐碎,没得心情翻译而且也在看<CLR vis C#>,所以断更了差不多5个月,现在继续翻译,保证会翻译完成,不会虎头蛇尾. 另:NUnit已经更新到2.6.3版本,虽然正在开 ...
- [翻译] Writing Property Editors 编写属性编辑器
Writing Property Editors 编写属性编辑器 When you select a component in the designer its properties are di ...
- 分析Runtime的属性Property
一.介绍 在OC中我们可以给任意的一个类以@property的格式声明属性,当然对于这个属性也会采用某一些属性关键字进行修饰,那么属性的真正的面目是啥样子的呢?其实,runtime源码中可以看到,pr ...
- iOS编码规范
The official raywenderlich.com Objective-C style guide. This style guide outlines the coding con ...
随机推荐
- shell 脚本编写基础
在进行Linux测试时编写脚本是必不可少的,Shell脚本的名称可以随便定义,也不要什么后缀名,例如可以写abc,smartzip这类名称,运行时只要键入 ./smartzip就能运行脚本了.. 每行 ...
- C# 获取 存储过程 返回值
C#获取存储过程的返回值,这一方法,总是容易忘,今天给贴出来,以方便下次使用 存储过程: CREATE PROCEDURE [dbo].[Proc_GetInfo] ), ) out ...
- 那些年我们遇到的坑(1)-Description Resource Path Location Type Archive for required library
在下载JAR包过程中遇到了错误,根据提示找到maven仓库报错的目录,将该目录下的所有文件删除重新下载即可
- Delphi、Lazarus保留字、关键字详解
Delphi.Lazarus保留字.关键字详解 来自橙子,万一的博客以及其他地方 保留字:变量等标识符可以再使用: 关键字:有特定含义,不能再次重新定义: 修饰字:类似保留字的功能,也就是说可以重用 ...
- Servlet会话管理二(Cookie)
Cookie是在HTTP协议下,将服务器传递给浏览器的的少量信息保存到浏览器客户端的一种技术,通过这种技术,即使在浏览器被关闭或链接中断的情况下,用户仍可以维护Cookie中的数据. Cookie是经 ...
- python文件读取操作、序列化
1.对文件进行读写操作时,先建立文件句柄 f = open("test.txt","r",encoding="UTF-8") 其中,r为文件 ...
- Python之路(第五篇) Python基本数据类型集合、格式化、函数
一.变量总结 1.1 变量定义 记录某种状态或者数值,并用某个名称代表这个数值或状态. 1.2 变量在内存中的表现形式 Python 中一切皆为对象,数字是对象,列表是对象,函数也是对象,任何东西都是 ...
- 如何烧写BIOS到SD卡里面
针对TINY6410 ADK型号 1.SD卡格式化为FAT32或者FAT格式 2.将SD卡插入USB接口的读卡器,并插在PC的USB口 3.“以管理员身份运行”SD-Flasher.exe(在tiny ...
- 如何安全管理windows系统日志,windows系统日志的报表和告警
如何安全管理windows系统日志,windows系统日志的报表和告警 无论大小,每个拥有IT基础设施的组织都容易发生内部安全攻击.您的损失等同于黑客的收益:访问机密数据.滥用检索到的信息.系统崩溃, ...
- rails 辅助方法
rails辅助方法全解: https://ruby-china.github.io/rails-guides/routing.html