Objective-C 属性参数
2012-02-04 23:09
134 查看
属性参数有以下三种Writability、Setter、Semantics Atomicity
Writability
These attributes specify whether or not a property has an associated set accessor. They are mutually exclusive.readwrite Indicates that the property should be treated as read/write. This attribute is the default.
readonly If you use the
@synthesizedirective in the implementation block, only the getter method is synthesized. Moreover, if you attempt to assign a value using the dot syntax, you get a compiler error.
Setter Semantics
These attributes specify the semantics of a set accessor. They are mutually exclusive.
strong
weak
copySpecifies that a copy of the object should be used for assignment.The previous value is sent a
releasemessage.The copy is made by invoking the
copymethod. This attribute is valid only for object types, which must implement the
NSCopyingprotocol.
指定应该使用对象的副本(深度复制),前一个值发送一条release消息。基本上像retain,但是没有增加引用计数,是分配一块新的内
存来放置它。
assgin Specifies that the setter uses simple assignment. This attribute is the default. You use this attribute for scalar types such as
NSIntegerand
CGRect.
setter方法直接赋值,而不进行retain操作,比如NSInteger和CGRect,它们不是对象,所以不用release。
retain Specifies that
retainshould be invoked on the object upon assignment.The previous value is sent a
releasemessage.
setter方法对参数进行release旧值,再retain新值 例如:
1.-(void) setObj:(ClassX*) value
2.{
3. if (obj != value)
4. {
5. [obj release];
6. obj = [value retain];
7. }
8.}
Atomicity
You can use this attribute to specify that accessor methods are not atomic. (There is no keyword to denote atomic.)
nonatomic Specifies that accessors are nonatomic. By default, accessors are atomic.
[align=right]Wangkeke 2012-02-04 23:09 发表评论[/align]
相关文章推荐
- objective - c的属性参数
- html 属性是可以自定义的(解决参数获取的问题)
- [bugfix]copy属性参数将NSMutableArray变为NSArray类型
- ASP.net中通过HyperLink的NavigateUrl属性传递参数,与新页面的Page_Load()接收参数
- 刨根问底Objective-C Runtime(4)- 成员变量与属性
- FusionCharts参数说明——3D饼图属性(Pie3D.swf )
- 【转】Objective-C 属性特性(assign , retain , copy , readonly , readwrite , atomic , nonatomic)
- struts2学习笔记----用action的属性接受参数
- Struts2中action接受参数的方法,属性:DomainModel、ModelDriver和ActionSupport
- Objective-C——属性与成员变量辨析
- Objective-C 函数参数理解
- js 获取函数的所有参数和遍历JavaScript某个对象所有的属性名称和值的方法
- Objective-C中@property所有的属性详解
- objective-c中property的属性
- 3 手写实现SpringMVC,第三节:通过反射给属性和参数注入值
- VB选项卡SSTAB属性及参数
- 有关flash属性参数详解
- highcharts图表史上最全的参数配置(属性+事件)
- iPhone开发:Objective-C属性修饰关键字使用详解
- Objective-C的属性和成员变量用法及关系浅析