@interface ViewController ()
@property (nonatomic,strong)NSArray *array;
@property (nonatomic,strong)NSArray *array2;
@property (nonatomic,strong)NSMutableArray *mutableArray;
@property (nonatomic,strong)NSMutableArray *mutableArray2;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.mutableArray = [NSMutableArray array];
for (int i = 0; i<10; i++) {
[self.mutableArray addObject:[NSString stringWithFormat:@"%d",i]];
}
self.array = [self.mutableArray copy];
self.array2 = [self.mutableArray mutableCopy];
self.mutableArray2= [self.mutableArray mutableCopy];
NSLog(@"%p %@",self.mutableArray,NSStringFromClass([self.mutableArray class]));
NSLog(@"%p %@ ",self.array,NSStringFromClass([self.array class]));
NSLog(@"%p %@",self.array2,NSStringFromClass([self.array2 class]));
NSLog(@"%p %@",self.mutableArray2,NSStringFromClass([self.mutableArray2 class]));
[self.mutableArray2 removeObjectAtIndex:5];
NSLog(@"%@",self.mutableArray2);
NSLog(@"%@",self.mutableArray);
NSLog(@"%@",self.array);
NSLog(@"%@",self.array2);
NSLog(@"------------");
[self.mutableArray removeObjectAtIndex:5];
NSLog(@"%@",self.mutableArray2);
NSLog(@"%@",self.mutableArray);
NSLog(@"%@",self.array);
NSLog(@"%@",self.array2);
}
2020-03-19 10:47:12.925740+0800 COPYandMutableCopy[5825:12859203] 0x6000002421c0 __NSArrayM
2020-03-19 10:47:12.925873+0800 COPYandMutableCopy[5825:12859203] 0x600000242370 __NSFrozenArrayM
2020-03-19 10:47:12.925955+0800 COPYandMutableCopy[5825:12859203] 0x6000002422b0 __NSArrayM
2020-03-19 10:47:12.926034+0800 COPYandMutableCopy[5825:12859203] 0x600000242190 __NSArrayM
2020-03-19 10:47:12.926144+0800 COPYandMutableCopy[5825:12859203] (
0,
1,
2,
3,
4,
6,
7,
8,
9
)
2020-03-19 10:47:12.926230+0800 COPYandMutableCopy[5825:12859203] (
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
)
2020-03-19 10:47:12.926327+0800 COPYandMutableCopy[5825:12859203] (
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
)
2020-03-19 10:47:12.926427+0800 COPYandMutableCopy[5825:12859203] (
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
)
2020-03-19 10:47:12.926507+0800 COPYandMutableCopy[5825:12859203] ------------
2020-03-19 10:47:12.926598+0800 COPYandMutableCopy[5825:12859203] (
0,
1,
2,
3,
4,
6,
7,
8,
9
)
2020-03-19 10:47:13.119880+0800 COPYandMutableCopy[5825:12859203] (
0,
1,
2,
3,
4,
6,
7,
8,
9
)
2020-03-19 10:47:13.120058+0800 COPYandMutableCopy[5825:12859203] (
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
)
2020-03-19 10:47:13.120204+0800 COPYandMutableCopy[5825:12859203] (
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
)
最后发现,NSArray 无论用copy还是mutablecopy都是一样
网友评论