• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Objective-C属性参数

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

属性参数有以下三种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 @synthesize directive 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
copy    Specifies that a copy of the object should be used for assignment.The previous value is sent a release message.The copy is made by invoking the copy
 
               method. This attribute is valid only for object types, which must implement the NSCopying  protocol.
                 指定应该使用对象的副本(深度复制),前一个值发送一条release消息。基本上像retain,但是没有增加引用计数,是分配一块新的内
                 存来放置它。

assgin Specifies that the setter uses simple assignment. This attribute is the default. You use this attribute for scalar types such as NSInteger and CGRect.
            setter方法直接赋值,而不进行retain操作,比如NSInteger和CGRect,它们不是对象,所以不用release。

retain Specifies that retain should be invoked on the object upon assignment.The previous value is sent a release message.
            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.

 



Wangkeke 2012-02-04 23:09 发表评论

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap