﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-加文-文章分类-苹果开发</title><link>http://www.cppblog.com/chxzwj/category/20506.html</link><description>      在这个世界上取得成就的人，都努力去寻找他们想要的机会，如果找不到机会，他们便自己创造机会。      -- 萧伯纳</description><language>zh-cn</language><lastBuildDate>Mon, 13 May 2013 11:22:31 GMT</lastBuildDate><pubDate>Mon, 13 May 2013 11:22:31 GMT</pubDate><ttl>60</ttl><item><title>Objective-C 属性列表上的各个常用属性值及其含义</title><link>http://www.cppblog.com/chxzwj/articles/199902.html</link><dc:creator>chxzwj</dc:creator><author>chxzwj</author><pubDate>Thu, 02 May 2013 06:39:00 GMT</pubDate><guid>http://www.cppblog.com/chxzwj/articles/199902.html</guid><wfw:comment>http://www.cppblog.com/chxzwj/comments/199902.html</wfw:comment><comments>http://www.cppblog.com/chxzwj/articles/199902.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/chxzwj/comments/commentRss/199902.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/chxzwj/services/trackbacks/199902.html</trackback:ping><description><![CDATA[assign &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;使用简单赋值语句为实例变量设置值<br />copy &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;使用copy方法设置实例变量的值<br />nonatomic &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="background-color: #ffffff; font-family: Arial; line-height: 26px;">直接返回值。若没有声明该属性，那么就是atomic属性，挤兑实例变量的存储是互斥锁定的。在没有垃圾回收的环境下，系统retain这个实例变量，并设置</span><span style="background-color: #ffffff; font-family: Arial; line-height: 26px;">autorelease 然后才返回值<br />readonly &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-family: Arial; line-height: 26px; background-color: #ffffff;">不能设置实例变量的值，编译器不生成setter'方法<br />readwrite &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="font-family: Arial; line-height: 26px; background-color: #ffffff;">可以获取并设置实例变量的值。在实现类文件中，使用@synthesize，编译器自动产生setter和getter方法<br />retain &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-family: Arial; line-height: 26px; background-color: #ffffff;">在赋值的时候执行retain（保持）操作<br />getter=name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="font-family: Arial; line-height: 26px; background-color: #ffffff;">取值方法使用name制定的名称，而不是实例变量的名称<br />setter=name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 赋值方法</span><span style="background-color: #ffffff;"><font face="Arial"><span style="line-height: 26px;">使用name制定的名称，而不是实例变量的名称</span></font><br /><br /><br /></span><div><span style="line-height: 26px;">这里的参数主要分为三类：</span></div><div><span style="line-height: 26px;">读写属性： （readwrite/readonly）</span></div><div><span style="line-height: 26px;">setter语意：（assign/retain/copy）</span></div><div><span style="line-height: 26px;">原子性： （atomicity（nonatomic）</span></div><div>assign/retain/copy 决定了以何种方式对数据成员赋予新值&nbsp;</div><div>atomicity的默认值是atomic，读取函数为原子操作。&nbsp;</div><div>经常用到的参数是 copy/reain/assign。</div><div>在其中选择一个来确定属性的setter如何处理这个属性。很多Objective-C中的object最好使用用retain，一些特别的object（例如：string）使用copy。&nbsp;</div><div>assign关键字代表setter直接赋值，而不是复制或者保留它。这种机制非常适合一些基本类型，比如NSInteger和CGFloat，或者你并不直接拥有的类型，比如delegates。&nbsp;</div><div>readonly关键字代表setter不会被生成， 所以它不可以和 copy/retain/assign组合使用。&nbsp;</div><div>在实现里,只需要</div><div>@synthesize mainView;</div><div>@synthesize window;</div><div>就可代替 繁琐的setter, getter方法, 这样就 可让编译器自动生成读写函数，定义了property, 使用者,可以 点号(.) 来存取属性了。</div><img src ="http://www.cppblog.com/chxzwj/aggbug/199902.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/chxzwj/" target="_blank">chxzwj</a> 2013-05-02 14:39 <a href="http://www.cppblog.com/chxzwj/articles/199902.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>