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 ...
随机推荐
- easyrules
http://www.easyrules.org/tutorials/hello-world-tutorial.html
- PHP 语句和时间函数
语句 1.分支语句 (1)if例子:$a=9;$b=5;if($a>$b){echo $a."比".$b."大";}else{echo $a." ...
- Servlet会话管理二(Cookie)
Cookie是在HTTP协议下,将服务器传递给浏览器的的少量信息保存到浏览器客户端的一种技术,通过这种技术,即使在浏览器被关闭或链接中断的情况下,用户仍可以维护Cookie中的数据. Cookie是经 ...
- [Robot Framework] 动态等待,提供默认的等待时间,等待时间可传可不传
默认10s
- Python之路番外(第二篇):PYTHON基本数据类型和小知识点
一.基础小知识点 1.如果一行代码过长,可以用续行符 \换行书写 例子 if (signal == "red") and \ (car == "moving") ...
- nginx指令中的优化(配置文件)
nginx指令中的优化(配置文件)worker_processes 8; nginx进程数,建议按照cpu数目来指定,一般为它的倍数.worker_cpu_affinity 00000001 0000 ...
- windows 与 Linux SOCKET通讯
windows client 端口 // Def_win_client_socket_test.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" ...
- css字符串转换为类map对象及反转
存储对象为啥是类map(即:{key:val,...}格式),因为Map对象的val为字符时,无法存储 '('.')' 左右括号,我也很无奈╮(╯▽╰)╭ 解析脚本: <!DOCTYPE htm ...
- 用php把access数据库导入到mysql
<?php header("content-Type: text/html; charset=utf-8"); /// ///把access数据库转换成mysql的SQL语句 ...
- 【转】四、可空类型Nullable<T>到底是什么鬼
[转]四.可空类型Nullable<T>到底是什么鬼 值类型为什么不可以为空 首先我们都知道引用类型默认值都是null,而值类型的默认值都有非null. 为什么引用类型可以为空?因为引用类 ...