I want to build an array of strings, that can point every time to a different string. I saw开发者_如何学编程 that I can use NSArray
and NSMutableArray
.
What is the difference between them?
Straight from Apple:
NSArray
NSMutableArray
Main difference:
NSArray is non-mutable, meaning it cannot be altered once it is created and is usually faster and carries less of a memory footprint than its mutable counterpart.
NSMutableArray can be changed after it is created.
There are more differences than just that, but the documentation goes over them better than I can. I also recommend watching the free IOS Development lectures from Stanford available on iTunes. They go into the different data structures and how they can be used in much greater depth.
NSMutableArray can be modified while NSArray cannot be modified after initializations (i.e addObjects, remove, etc..) If you need to add the strings after initializations go with mutable arrays
With NSMutableArray
, you can add objects and remove objects dynamicaly.
See :
difference-b-w-nsarray-and-nsmutablearray
You can initialize it by :
NSMutableArray *ma = [[NSMutableArray alloc]init];
[ma addObject:myObject];
精彩评论