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 ...
随机推荐
- Class 'com.mchange.v2.c3p0.ComboPooledDataSource' not found [config set
解决方法: 修改maven <dependency> <groupId>c3p0</groupId> <artifactId>c3p0</arti ...
- HTML&&css练习
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- redis 数据类型为list命令整理以及示例
常用来制作队列,当然lpush+rpop也能做栈 #将RPUSH RPUSHX LPUSH LPUSHX一并介绍(具体介绍RPUSH和RPUSHX,因为其实就是插入的方向的区别) RPUSH key ...
- Mac 下配置Nginx安装环境配置详细说明
环境信息: Mac OS X 10.11.1 Homebrew 0.9.5 正文 一.安装 Nginx 1.终端执行: ? 1 2 brew search nginx brew install ng ...
- MySQL学习笔记-数据库内存
数据库内存 InnoDB存储引擎内存由以下几个部分组成:缓冲池(buffer pool).重做日志缓冲池(redo log buffer)以及额外的内存池(additional memory pool ...
- 小话C源码移植
我们知道国外很多程序员工作在linux / unix 环境下,所以有很多优秀的c/c++语言代码不能直接在windows平台进行编译. 很多时候我们只能使用msys, cmake等工具进行模拟环境编译 ...
- delphi程序设计改进可读性一法
Delphi,Lazarus程序设计改进一法 作者:steven QQ:1565498246 Delphi/Lazarus有一个思想就是方法.函数名调用,后边可以不使用括号(),比如调用函数Now,这 ...
- 英国BBC出的这套中国风海报,设计美哭了!
“中国风”在国际上已经不是“小众”了 之前分享过好莱坞电影的中国风海报 没想到国外的电视剧也看上了中国市场 没错就是英国BBC的最长寿科幻剧—— <神秘博士Doctor Who> 前段时间 ...
- 当前页面刷新和动态添加控件的jquery事件绑定on
当前页面刷新(console): location.reload() 给动态添加的控件添加js事件(委托): <ul> <li>菜单一</li> <li> ...
- refused to Connection
两种情况: .数据库账号密码错误 .mysql挂了