Beginning IOS 7 Development Exploring the IOS SDK - Navigation Controllers and Table Views

Note You may notice that the familyNames property is declared using the copy keyword instead of strong. What’s up with that? Why should we be copying arrays willy-nilly? The reason is the potential existence of mutable arrays.

Imagine if we had declared the property using strong, and an outside piece of code passed in an instance of NSMutableArray to set the value of the familyNames property. If that original caller later decides to change the contents of that array, the BIDRootViewController instance will end up in an inconsistent state, where the contents of familyNames is no longer in sync with what’s on the screen! Using copy eliminates that risk, since calling copy on any NSArray (including any mutable subclasses) always gives
us an immutable copy. Also, we don’t need to worry about the performance impact too much. As it turns out,
sending copy to any immutable object doesn’t actually copy the object. Instead, it returns the same object
after increasing its reference count. In effect, calling copy on an immutable object is the same as calling
retain, which is what ARC might do behind the scenes anytime you set a strong property. So, it works out
just fine for everyone, since the object can never change.

This situation applies to all value classes where the base class is immutable, but mutable subclasses exist.
These value classes include NSArray, NSDictionary, NSSet, NSString, NSData, and a few more.
Any time you want to hang onto an instance of one of these in a property, you should probably declare the
property’s storage with copy instead of strong to avoid any problems.

时间: 2024-10-26 06:41:21

Beginning IOS 7 Development Exploring the IOS SDK - Navigation Controllers and Table Views的相关文章

从零开始学ios开发(十五):Navigation Controllers and Table Views(中)

这篇内容我们继续上一篇的例子接着做下去,为其再添加3个table view的例子,有了之前的基础,学习下面的例子会变得很简单,很多东西都是举一反三,稍稍有些不同的内容,好了,闲话少说,开始这次的学习. 如果没有上一篇的代码,可以从这里下载Nav_1 1)第三个subtableview:Controls on Table Rows这个例子,我们将为每个table view的每一行添加一个按钮,这个按钮将放在accessory icon的位置(之前我们使用过accessoryType,其实这也是一个

从零开始学ios开发(十四):Navigation Controllers and Table Views(上)

这一篇我们将学习一个新的控件Navigation Controller,很多时候Navigation Controller是和Table View紧密结合在一起的,因此在学习Navigation Controller的同时,我们还将继续学习Table View其他一些特性,毕竟Navigation Controller还是相对来说毕竟简单的,没有什么太大的花头,它的主要作用就是一个view的切换,切来切去,而Table View的花头就比较多了,这次我们将这2个控件结合在一起进行学习. 再多说一

翻译Beginning iOS 7 Development中文版

不会iOS开发好像真的说不过去,来本中文版的Beginning iOS 7 Development吧. 看了Beginning iOS 7 Development这本书,感觉蛮不错的.全英文的,没有中文版. 看到有很多人求中文版的帖子,想抽个时间翻译一下,不知道需求大不大. 如果有人看到我的这篇文章,并且有中文版需求,那么请发个评论. 英文版高清下载地址:http://download.csdn.net/detail/fylz1125/7549069 如果评论达到50条的话,我就翻译这本书,在我

41889 - Application Development in the iOS Environment

Faculty of Engineering and Information TechnologySchool of Software41889 - Application Development in the iOS Environment42889 - iOS Application DevelopmentAutumn 2018Assessment Task 2Individual programming project: BubblePop GameDue 10 May 2019 at 1

iOS 7 Development Tips, Tricks & Hacks

iOS 7 Development Tips, Tricks & Hacks September 18, 2013 Like with any new iOS version there are a bunch of new tricks and hacks to work out. Here are a few things that weren't immediately obvious to me, it's in no way a complete set, just things th

iOS Mobile Development: Using Xcode Targets to Reuse the Code 使用xcode targets来实现代码复用

In the context of iOS mobile app development, a clone is simply an app that is based off another mobile app. A clone usually has more or less the same code base with probably a slightly different functionality. It’s quite common for this app to have

iOS 平台 Cocos2d-x 项目接入新浪微博 SDK 的坑

iOS 平台 Cocos2d-x 项目接入新浪微博 SDK 的坑 最近在做一个 iOS 的 cocos2d-x 项目接入新浪微博 SDK 的时候被“坑”了,最后终于顺利的解决了.发现网上也有不少人遇到一样的问题,但是能找到的数量有限的解决办法写得都不详细,很难让人理解,我来深入的写一写. 我的开发环境 Mac OS X 10.10.1 Xcode 6.1.1 (6A2008a) Cocos2d-x 3.2 新浪微博 SDK for iOS 2015 年 1 月 5 日从 github clone

《转》iOS 平台 Cocos2d-x 项目接入新浪微博 SDK 的坑

最近在做一个 iOS 的 cocos2d-x 项目接入新浪微博 SDK 的时候被“坑”了,最后终于顺利的解决了.发现网上也有不少人遇到一样的问题,但是能找到的数量有限的解决办法写得都不详细,很难让人理解,我来深入的写一写. 我的开发环境 Mac OS X 10.10.1 Xcode 6.1.1 (6A2008a) Cocos2d-x 3.2 新浪微博 SDK for iOS 2015 年 1 月 5 日从 github clone 的版本 遇到的问题 根据新浪微博 SDK 附带的文档接入项目后,

BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第1章节--SharePoint 2013 介绍 逐渐了解SharePoint

BEGINNING SHAREPOINT? 2013 DEVELOPMENT 第1章节--SharePoint 2013 介绍 逐渐了解SharePoint 简单地说,SharePoint 2013(以及以后的版本)是一个支持协同的平台----一个集中的基于Web的门户,你用来管理自己的和同事的文档.社交活动.数据和信息.这个定义非常广泛,但是用一个情形来概括就是:你在每天的基础上管理项目,同时必须也要管理项目中的人的团队.项目中,人们会开会,创建文档,交流观点,管理日程等等.如果没有一个集中的