iOS开发 - 怎么在集合对象中保存弱引用
iOS开发 - 如何在集合对象中保存弱引用
1.iOS6之前的做法
=== Code ===
2014-04-01 15:05:41.715 test[9915:60b] object.retainCount 1
2014-04-01 15:05:41.715 test[9915:60b] object.retainCount 1
1.iOS6之前的做法
NSValue *value = [NSValue valueWithNonretainedObject:myObj]; [array addObject:value];2.现在的做法
=== Code ===
NSObject *object = [[NSObject alloc] init]; NSLog(@"object.retainCount %i", object.retainCount); NSHashTable *hashTable = [NSHashTable weakObjectsHashTable]; [hashTable addObject:object]; NSLog(@"object.retainCount %i", object.retainCount);==== Log ===
2014-04-01 15:05:41.715 test[9915:60b] object.retainCount 1
2014-04-01 15:05:41.715 test[9915:60b] object.retainCount 1