Ios-copy&mutablecopy

Source: Internet
Author: User

1, for non-container objects (NSString)

Immutable (NSString)

Copy: Shallow copy, pointer pointing

Mutablecopy: Deep copy, generating variable string object

Variable (nsmutablestring)

Copy: Deep copy, generation of immutable string object

Mutablecopy: Deep copy, generating variable string object

2, for the Container class object array

Immutable (Nsarray)

Copy: Shallow copy, pointer pointing

Mutablecopy: Deep copy, generating a mutable array object (However, the object in the array is not processed, the object in the array is shallow copy)

Variable (nsmutablearray)

Copy: Deep copy, generating immutable group objects

Mutablecopy: Deep copy, generating immutable group objects

Test

NSString *STR1 =@"123"; NSLog (@"%p", STR1); NSString*STR2 =[str1 copy]; NSLog (@"%p", STR2); Nsmutablestring*STR3 =[str1 mutablecopy]; NSLog (@"%p", STR3); Nsmutablestring*STR4 = [[nsmutablestring alloc]initwithstring:@"123"]; NSLog (@"%p", STR4); NSString*STR5 =[STR4 copy]; NSLog (@"%p", STR5); Nsmutablestring*STR6 =[STR4 mutablecopy]; NSLog (@"%p", STR6); Nsarray*array1 = [[Nsarray alloc] initwithobjects:@3,@4, nil]; NSLog (@"%p", array1); Nsarray*array2 =[array1 copy]; NSLog (@"%p", array2); Nsmutablearray*array3 =[Array1 mutablecopy]; NSLog (@"%p", ARRAY3); Nsmutablearray*array4 = [[Nsmutablearray alloc]initwithobjects:@2,@3, nil]; NSLog (@"%p", Array4); Nsarray*array5 =[array4 copy]; NSLog (@"%p", Array5); Nsmutablearray*array6 =[Array4 mutablecopy]; NSLog (@"%p", Array6);
 .- ,- at Ten: Wu:50.878[1364:147504]0X10409CC90 .- ,- at Ten: Wu:53.636[1364:147504]0X10409CC90 .- ,- at Ten: Wu:53.636[1364:147504]0x7fd602d1c330 .- ,- at Ten: Wu:54.322[1364:147504]0x7fd602dae190 .- ,- at Ten: Wu:54.323[1364:147504]0xa000000003332313 .- ,- at Ten: Wu:54.323[1364:147504]0x7fd602e07420 .- ,- at Ten: Wu:55.924[1364:147504]0x7fd602d00d60 .- ,- at Ten: Wu:56.750[1364:147504]0x7fd602d00d60 .- ,- at Ten: Wu:56.750[1364:147504]0x7fd602c11050 .- ,- at Ten: Wu:56.751[1364:147504]0x7fd602c2bfc0 .- ,- at Ten: Wu:56.751[1364:147504]0x7fd602c0a070 .- ,- at Ten: Wu:56.751[1364:147504]0x7fd602c0a220

3, Nshashtable-nsmaptable

Nshashtable and-nsmaptable are container class objects that appear after iOS 6, and one of the features is that you can set them as weak references to objects that you add to them.

Instead of adding objects such as arrays, the default object reference count adds 1, a strong reference, and a somewhat similar (weak,assgin) container

-(Instancetype) Initwithoptions: (nspointerfunctionsoptions) options Capacity: (Nsuinteger) initialcapacity NS_ Designated_initializer;typedef ns_options (Nsuinteger, nspointerfunctionsoptions) {//Memory Options is mutually exclusive//default is strongNspointerfunctionsstrongmemory ns_enum_available (10_5, 6_0) = (0UL<<0),//Use strong write-barrier to backing store, use GC memory on CopyIn#if(Target_os_mac &&!) (target_os_embedded | | Target_os_iphone)) | | Target_os_win32nspointerfunctionszeroingweakmemory Ns_enum_deprecated_mac (10_5, 10_8)= (1UL<<0),//deprecated; uses GC weak read and write barriers, and dangling pointer behavior otherwise#endifnspointerfunctionsopaquememory ns_enum_available (10_5, 6_0)= (2UL<<0), Nspointerfunctionsmallocmemory ns_enum_available (10_5, 6_0)= (3UL<<0),//Free () 'll be called on removal, calloc on CopyInNspointerfunctionsmachvirtualmemory ns_enum_available (10_5, 6_0) = (4UL<<0), nspointerfunctionsweakmemory ns_enum_available (10_8, 6_0)= (5UL<<0),//uses weak read and write barriers appropriate for ARC or GC//personalities is mutually exclusive//default is Object. As a special case, ' strong ' memory used for Objects would do retain/release under NON-GCNspointerfunctionsobjectpersonality ns_enum_available (10_5, 6_0) = (0UL<<8),//Use-hash and-isequal, Object descriptionNspointerfunctionsopaquepersonality ns_enum_available (10_5, 6_0) = (1UL<<8),//Use shifted pointer hash and direct equalityNspointerfunctionsobjectpointerpersonality ns_enum_available (10_5, 6_0) = (2UL<<8),//Use shifted pointer hash and direct equality, object descriptionNspointerfunctionscstringpersonality ns_enum_available (10_5, 6_0) = (3UL<<8),//Use a string hash and strcmp, description assumes UTF-8 contents; recommended for UTF-8 (or ASCII, which is a subset) Only CStringsNspointerfunctionsstructpersonality ns_enum_available (10_5, 6_0) = (4UL<<8),//Use a memory hash and memcmp (using the SIZE function you must set)Nspointerfunctionsintegerpersonality ns_enum_available (10_5, 6_0) = (5UL<<8),//Use unshifted value as hash & equalityNspointerfunctionscopyin ns_enum_available (10_5, 6_0)= (1UL<< -),//The memory acquire function would be asked to allocate and copy items on input};

4. Keychain API in IOS

iOS Keychian should be a system-level singleton, the information stored in it, the degree of security is higher,

Different apps can use the same key, the degree of information, simple implementation of information sharing between different apps a way of thinking

Ios-copy&mutablecopy

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.