0

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?

jscs
  • 63,694
  • 13
  • 151
  • 195
YosiFZ
  • 7,792
  • 21
  • 114
  • 221

3 Answers3

0

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];
Community
  • 1
  • 1
Michaël
  • 6,676
  • 3
  • 36
  • 55
0

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.

diceguyd30
  • 2,742
  • 20
  • 18
0

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

Sami
  • 1,369
  • 14
  • 35
  • and if i want to make him in a size that i will set?? how i will need to initialize him? – YosiFZ Mar 28 '11 at 18:48
  • If you are using NSMutableArray, there is no need to initialize it with specified capacity. However you can use initWithCapacity which will have enough size to hold this number of object. So you can use either of them.. But when you are dealing with NSArray, you have to initialize it with another array or objects or contents of a file. – Sami Mar 29 '11 at 11:56