標籤:
1、對於非容器物件(NSString)
不可變 (NSString)
copy :淺複製,指標指向
mutableCopy:深複製,產生可變字串對象
可變(NSMutableString)
copy: 深複製,產生不可變字串對象
mutableCopy :深複製,產生可變字串對象
2、對於容器類對象 數組
不可變(NSArray)
copy :淺複製,指標指向
mutableCopy:深複製,產生可變數組對象(但,數組中的對象沒有進行處理的話,數組的中的對象是淺複製)
可變(NSMutableArray)
copy :深複製,產生不可變數組對象
mutableCopy:深複製,產生不可變數組對象
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);
2016-08-23 10:54:50.878 [1364:147504] 0x10409cc902016-08-23 10:54:53.636 [1364:147504] 0x10409cc902016-08-23 10:54:53.636 [1364:147504] 0x7fd602d1c3302016-08-23 10:54:54.322 [1364:147504] 0x7fd602dae1902016-08-23 10:54:54.323 [1364:147504] 0xa0000000033323132016-08-23 10:54:54.323 [1364:147504] 0x7fd602e074202016-08-23 10:54:55.924 [1364:147504] 0x7fd602d00d602016-08-23 10:54:56.750 [1364:147504] 0x7fd602d00d602016-08-23 10:54:56.750 [1364:147504] 0x7fd602c110502016-08-23 10:54:56.751 [1364:147504] 0x7fd602c2bfc02016-08-23 10:54:56.751 [1364:147504] 0x7fd602c0a0702016-08-23 10:54:56.751 [1364:147504] 0x7fd602c0a220
3、NSHashTable -NSMapTable
NSHashTable 和 -NSMapTable是iOS 6 後出現的容器類對象,他有一個特點就是,對加入其中的對象,可以設定其為弱引用,
而不是像數組等容器加入對象後預設對象引用計數會加1,強引用,有點類似(weak,assgin)的容器
- (instancetype)initWithOptions:(NSPointerFunctionsOptions)options capacity:(NSUInteger)initialCapacity NS_DESIGNATED_INITIALIZER;typedef NS_OPTIONS(NSUInteger, NSPointerFunctionsOptions) { // Memory options are mutually exclusive // default is strong NSPointerFunctionsStrongMemory 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_WIN32 NSPointerFunctionsZeroingWeakMemory NS_ENUM_DEPRECATED_MAC(10_5, 10_8) = (1UL << 0), // deprecated; uses GC weak read and write barriers, and dangling pointer behavior otherwise #endif NSPointerFunctionsOpaqueMemory NS_ENUM_AVAILABLE(10_5, 6_0) = (2UL << 0), NSPointerFunctionsMallocMemory NS_ENUM_AVAILABLE(10_5, 6_0) = (3UL << 0), // free() will be called on removal, calloc on copyIn NSPointerFunctionsMachVirtualMemory 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 are mutually exclusive // default is object. As a special case, ‘strong‘ memory used for Objects will do retain/release under non-GC NSPointerFunctionsObjectPersonality NS_ENUM_AVAILABLE(10_5, 6_0) = (0UL << 8), // use -hash and -isEqual, object description NSPointerFunctionsOpaquePersonality NS_ENUM_AVAILABLE(10_5, 6_0) = (1UL << 8), // use shifted pointer hash and direct equality NSPointerFunctionsObjectPointerPersonality NS_ENUM_AVAILABLE(10_5, 6_0) = (2UL << 8), // use shifted pointer hash and direct equality, object description NSPointerFunctionsCStringPersonality 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 cstrings NSPointerFunctionsStructPersonality NS_ENUM_AVAILABLE(10_5, 6_0) = (4UL << 8), // use a memory hash and memcmp (using size function you must set) NSPointerFunctionsIntegerPersonality NS_ENUM_AVAILABLE(10_5, 6_0) = (5UL << 8), // use unshifted value as hash & equality NSPointerFunctionsCopyIn NS_ENUM_AVAILABLE(10_5, 6_0) = (1UL << 16), // the memory acquire function will be asked to allocate and copy items on input};
4、iOS 中的Keychain API
ios 中的keychian 應該是一個系統級的單例,在裡面存的資訊,安全的程度比較高,
不同的app可以通過相同的key,度取相關的資訊,簡單實現不同app之間的資訊共用一種思路
iOS -copy&mutableCopy