- // create an immutable array
- NSArray *arr = [NSArray arrayWithObjects: @"one", @"two", @"three", nil ];
-
- // create a mutable copy, and mutate it
- NSMutableArray *mut = [arr mutableCopy];
- [mut removeObject: @"one"];
-
- NSMutableArray *mut1 = [mut mutableCopy];
- [mut1 removeObjectAtIndex:0];
-
- NSMutableArray *mut2 = [NSMutableArray arrayWithObjects:@"A", @"B", nil];
- NSMutableArray *mut2_immut = [mut2 copy];
- //crash here
- //[myArray_immut removeObjectAtIndex:0];
-
- // Copys object, result is mutable
- NSMutableArray *mut2_mut = [mut2 mutableCopy];
- [mut2_mut removeObjectAtIndex:0];
复制代码
|
|