Beginning iOS 7 Development exploring the iOS sdk-navigation Controllers and Table views

Source: Internet
Author: User

Note 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 a 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 this array, the Bidrootviewcontroller instance would end up In a inconsistent state, where the contents of Familynames are no longer in sync with what's on the screen! Using copy eliminates, 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 objectafter increasing its reference count. In effect, calling copy on a immutable object is the same as Callingretain, which are what ARC might do behind the scenes Anytime set a strong property. So, it works outjust fine for everyone, since the object can never a change.

This situation applies to all value classes where the base class was immutable, but mutable subclasses exist. These value classes include Nsarray, Nsdictionary, Nsset, NSString, NSData, and a few more.
Any time your want to onto an instance of one of the these in a property, you should probably declare Theproperty ' s Storag E with copy instead of strong to avoid any problems.

Beginning iOS 7 Development exploring the iOS sdk-navigation Controllers and Table views

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.