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.

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

  1. 从零开始学ios开发(十六):Navigation Controllers and Table Views(下)

    终于进行到下了,这是关于Navigation Controllers和Table Views的最后一个例子,稍微复杂了一点,但也仅仅是复杂而已,难度不大,我们开始吧. 如果没有上一篇的代码,可以从这里 ...

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

    这篇内容我们继续上一篇的例子接着做下去,为其再添加3个table view的例子,有了之前的基础,学习下面的例子会变得很简单,很多东西都是举一反三,稍稍有些不同的内容,好了,闲话少说,开始这次的学习. ...

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

    这一篇我们将学习一个新的控件Navigation Controller,很多时候Navigation Controller是和Table View紧密结合在一起的,因此在学习Navigation Co ...

  4. 翻译Beginning iOS 7 Development中文版

    不会iOS开发好像真的说只是去,来本中文版的Beginning iOS 7 Development吧. 看了Beginning iOS 7 Development这本书,感觉蛮不错的.全英文的,没有中 ...

  5. 李洪强iOS开发之-环信02_iOS SDK 介绍及导入

    李洪强iOS开发之-环信02_iOS SDK 介绍及导入 iOS SDK 介绍及导入 iOS SDK 介绍 环信 SDK 为用户开发 IM 相关的应用提供的一套完善的开发框架.包括以下几个部分: SD ...

  6. 李洪强iOS开发之-环信01_iOS SDK 前的准备工作

    李洪强iOS开发之-环信01_iOS SDK 前的准备工作 1.1_注册环信开发者账号并创建后台应用 详细步骤:  注册并创建应用 注册环信开发者账号 第 1 步:在环信官网上点击“即时通讯云”,并点 ...

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

    最近在做一个 iOS 的 cocos2d-x 项目接入新浪微博 SDK 的时候被“坑”了,最后终于顺利的解决了.发现网上也有不少人遇到一样的问题,但是能找到的数量有限的解决办法写得都不详细,很难让人理 ...

  8. iOS Swift WisdomScanKit图片浏览器功能SDK

    iOS Swift WisdomScanKit图片浏览器功能SDK使用 一:简介      WisdomScanKit 由 Swift4.2版编写,完全兼容OC项目调用. WisdomScanKit的 ...

  9. iOS Swift WisdomKeyboardKing 键盘智能管家SDK

    iOS Swift WisdomKeyboardKing 键盘智能管家SDK [1]前言:    今天给大家推荐个好用的开源框架:WisdomKeyboardKing,方面iOS日常开发,优点和功能请 ...

  10. 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 mob ...

随机推荐

  1. Optimum + ONNX Runtime: 更容易、更快地训练你的 Hugging Face 模型

    介绍 基于语言.视觉和语音的 Transformer 模型越来越大,以支持终端用户复杂的多模态用例.增加模型大小直接影响训练这些模型所需的资源,并随着模型大小的增加而扩展它们.Hugging Face ...

  2. java-tocsv

    1.依赖 <dependencies> <dependency> <groupId>org.apache.poi</groupId> <artif ...

  3. 报错解决:DENIED Redis正在保护模式下运行

    DENIED Redis正在保护模式下运行,因为已启用保护模式,未指定绑定地址,也未向客户端请求身份验证密码.在此模式下,仅接受环回接口的连接.如果您想从外部计算机连接到Redis,您可以采用以下解决 ...

  4. DataTransfer.setDragImage()自定义拖拽图像遇到的坑

    发生拖动时,从拖动目标(dragstart事件触发的元素)生成半透明图像,并在拖动过程中跟随鼠标指针.这个图片是自动创建的,你不需要自己去创建它.然而,如果想要设置为自定义图像,那么 DataTran ...

  5. 初始化控件panel大小和相对父容器居中

    /// <summary> /// 初始化界面大小 /// </summary> protected void InitForm() { int winwith = Scree ...

  6. js 对象命名

    JS 标识符的命名规则,即变量的命名规则: 标识符只能由字母.数字.下划线和'$'组成 数字不可以作为标识符的首字符 对象属性的命名规则 通过[]操作符为对象添加属性时,属性名称可以是任何字符串(包括 ...

  7. 统计tomcat的access日志

    统计tomcat的access日志的ip次数,并按次数排序 awk '{sum[$1]++}END{for(i in sum) print i "\t" sum[i]}' loca ...

  8. c++练习266题:楼层编号

    *266题 原题传送门:http://oj.tfls.net/p/266 题解: #include<bits/stdc++.h>using namespace std; int t;//高 ...

  9. # HUAWEI--IPv6 over IPv4隧道配置(简单案例)

    HUAWEI--IPv6 over IPv4隧道配置(简单案例) 拓扑图 项目要求: PC3和PC4使用的IPv6的地址,路由和路由器之间的连接使用IPv4的地址并使用静态路由连接,路由器和PC机的连 ...

  10. Maven使用tomcat7-maven插件部署项目问题

    Cannot invoke Tomcat manager: Connection refused: connect -> [Help 1] 检查tomcat-users.xml的用户配置,用户权 ...