tags:

views:

70

answers:

3

Hi, everyone,

I want to ask a question about the objective C. When I study the library from the apple developer website. I always see that there are some subclass called "mutable". For example, the NSArray and NSMutableArray. What does it mean about this word. Are there some special meaning? Can anyone tell me? Thank you.

+4  A: 

It means you can change its values. If you look at the NSMutableArray docs, you'll see it defines extra methods like -addObject:. NSArray by itself doesn't have these (and can thus be more efficient / take less memory in implementation).

Also note, if you call [myMutableArray copy] you'll get a non-mutable copy of it (which you must later release0. And similarly there's -mutableCopy.

jtbandes
+1  A: 

Mutable means you can change it. Look at the difference between addObject in NSMutableArray and arrayByAddingObject in NSArray.

Lou Franco
+1  A: 

From the Objective-C Beginner's Guide it states the answer to your specific question:

There are two kinds of arrays (and of usually most data oriented Foundation classes) NSArray and NSMutableArray. As the name suggests, Mutable is changable, NSArray then is not. This means you can make an NSArray but once you have you can't change the length.

This tech note also implies you can change the length of a mutable array after the array has been created.

In general mutability stems from these meanings. This will help provide a more broad understanding for when you encounter it elsewhere.

John K