In UITabBar.h, a propery signed copy
@property(nonatomic,copy) NSArray *items; // get/set visible
It’s a array
And what “copy” means?
copy NSArray container obj?
copy every obj NSArray contains?
or something.
so there’s a test
UITabBar* testBar = [[UITabBar alloc] init];
UITabBarItem* item = [[UITabBarItem alloc] init];
NSArray* array = [[NSArray alloc] initWithObjects:item, nil];
NSLog(@"bar:%p,%d", testBar, testBar.retainCount);
NSLog(@"item:%p,%d", item, item.retainCount);
NSLog(@"array:%p,%d", array, array.retainCount);
testBar.items = array;
NSLog(@"that item:%p,%d", [testBar.items lastObject], [[testBar.items lastObject] retainCount]);
NSLog(@"testBar.items:%p,%d", testBar.items, testBar.items.retainCount);
result
bar:0x96a9750,1
item:0x96aa230,2
array:0x96aa280,1
that item:0x96aa230,2
testBar.items:0x96aa280,6
why neither container array nor obj in array has been “copied”?
The reason the copy has not been made in this case is that
NSArrayis immutable. You do not need to make a copy of it to guard against changes to the array, because such changes cannot be made; it is sufficient to retain the same immutable array.If you try this experiment with
NSMutableArray, you will get a different result.