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. 2021昆明B

    容斥 + 矩形面积并 + 状压dp B-Blocks_第46届ICPC亚洲区域赛(昆明)(正式赛) (nowcoder.com) 题意 给出一个矩形A \((0,0),(W,H)\), 给出 \(n\ ...

  2. 【MySQL】导出到CSV

    http://www.yiidian.com/mysql/mysql-export-table-to-cvs.html 要将表导出为 CSV 文件,我们将使用SELECT INTO....OUTFIL ...

  3. Matplotlib 绘图线

    绘图过程如果我们自定义线的样式,包括线的类型.颜色和大小等. 线的类型 线的类型可以使用 linestyle 参数来定义,简写为 ls. 类型 简写 说明 'solid' (默认) '-' 实线 'd ...

  4. N63050 第三周运维作业

    五.文本处理工具和正则表达式1.基本正则表达式(53分钟)2.基本正则表达式和扩展正则表达式(50分钟)3.文本处理三剑客之grep(43分钟)4.shell脚本编程基础知识(14分钟)5.shell ...

  5. LinuxGPU服务器搭建

    (1)驱动与cuda下载: https://www.nvidia.cn/Download/Find.aspx?lang=cn (2)执行以下命令进行安装,文件名替换为自己的. sudo sh NVID ...

  6. 预处理指令详解(C语言

    一.预处理符号 预处理符号是C语言内置的符号,是可以直接使用的. 其中,若遵顼ANSI C,则__STDC__ 为1,否则未定义. 二.#define 1)定义标识符 define可以用来定义标识符, ...

  7. git基础代码获取

    1.新建文件夹 2.使用命令git init 初始化 3.见你与远程厂库的连接,git remote add origin 远程仓库地址 4.将远程仓库代码拉去到本地,git fetch origin ...

  8. ps 合并两张图片为一张

    打开PS并点击左上角的"文件":之后再点击"打开"(也可以按下快捷键"Ctrl+O"),打开文件选择窗口. 2 在打开的文件选择窗口中,找到 ...

  9. 腾讯云静态资源放到cos存储桶里,并开启CDN自定义域名加速

    首先根据腾讯云cos对应文档创建cos存储桶(权限为共有读私有写),上传build之后的静态文件到存储桶根目录,然后配置静态网站,然后访问静态网站的访问节点,如果报错请配置索引文档和错误文档为inde ...

  10. vue去除富文本的标签和样式

    vue利用正则去除富文本的标签和样式 ts: const removeHtmlStyle =(html :any)=> { let relStyle = /style\s*?=\s*?(['&q ...