zoukankan      html  css  js  c++  java
  • Beginning IOS 7 Development Exploring the IOS SDK

    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. 

  • 相关阅读:
    线程
    管道,数据共享,进程池
    进程锁,队列,JoinableQueue
    网络基础之 并发编程之进程,多路复用,multiprocess模块
    网络基础之 tcp/ip五层协议 socket
    python基础之 026 包以及包的引入
    python基础之 025 模块加载与import的使用
    python基础之正则表达式 re模块
    python基础之 序列 pickle&json
    【SoapUI】SoapUI projects 01
  • 原文地址:https://www.cnblogs.com/BruceWayne09/p/4976595.html
Copyright © 2011-2022 走看看