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. uniapp 自定义 picker

    前言 我们在开发的过程中经常会遇到现有插件无法满足需求的情况,毕竟不是组件库不能满足项目所有需求,这时就需要我们自己去构建组件. 写这篇博文也是记录我平时开发的,以后可能会用得到的东西.希望大家看到本 ...

  2. jquery获得标签元素

    一.根据元素name值获取元素 $("元素[name="name的值"]"); 例子:1.$("a[name="apoint"]& ...

  3. ROS1 Qt5 CMake基本配置

    ############################################################################## # CMake ############# ...

  4. gateway添加跨域配置

    import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Co ...

  5. Vulnhub:CK-00靶机

    kali:192.168.111.111 靶机:192.168.111.196 信息收集 端口扫描 nmap -A -v -sV -T5 -p- --script=http-enum 192.168. ...

  6. python + pyqt 实现的你下载css背景图片的小工具(最终版)

    学习python有三个星期了,算是做的第一个小工具,其实也没必要做成图形界面,只是为的GUI学习(再说技术总归给人使用的,熟练很多shell命令只是个"匠人".) win8下面: ...

  7. finalshell如何查看密码

    1.右键点击导出 2.打开导出的配置文件,搜索password,找到password的编码后的字符串复制 3.运行下面代码,即可查看原来的密码,把main()方法的字符串替换成上一步复制的字符串imp ...

  8. The table‘xxxx’is full

    df -h 查看磁盘 设置 back_log = 50 接受队列,对于没建立 tcp 连接的请求队列放入缓存中,队列大小为 back_log,受限制与 OS 参数,试图设定 back_log 高于你的 ...

  9. JDK卸载与JDK12 安装

    JDK卸载与JDK12 安装 一.JDK卸载 控制面板>程序和功能>jdk程序(java 8 update 391:java SE Development Kit8 update 391) ...

  10. OpenStack 卷虚拟机跨租户迁移方案

    目标:迁移租户A的卷虚机到租户B 场景:使用卷虚拟机,租户a和b使用相同网络 租户A的操作: 1.记录虚拟机的ip地址,Mac信息, nova interface-list neutron port- ...