Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of the "mutable" in objective C?

Tags:

objective-c

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.

like image 816
Questions Avatar asked Aug 12 '10 01:08

Questions


People also ask

What is mutable array Objective C?

Overview. The NSMutableArray class declares the programmatic interface to objects that manage a modifiable array of objects. This class adds insertion and deletion operations to the basic array-handling behavior inherited from NSArray .

What do you mean by mutable object?

A mutable object is an object whose state can be modified after it is created. Immutables are the objects whose state cannot be changed once the object is created. Strings and Numbers are Immutable.

What is mutable and immutable in C?

Mutable and immutable are English words meaning "can change" and "cannot change" respectively. The meaning of the words is the same in the IT context; i.e. a mutable string can be changed, and. an immutable string cannot be changed.

What is a mutable datatype?

Mutable data types are those whose values can be changed or new values can be assigned to them. List, Sets, and Dictionary in Python are examples of some mutable data types in Python. Immutable data types are those, whose values cannot be modified once they are created.

What is immutable at objective?

In object-oriented and functional programming, an immutable object (unchangeable object) is an object whose state cannot be modified after it is created.

Why do we use mutable object?

You need mutable classes to deal with situations when transforming a class from state A to state Z would produce a lot of intermediate objects, which you would rather not spend time creating. One classic example is concatenating an array of strings.


2 Answers

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.

like image 172
jtbandes Avatar answered Sep 21 '22 01:09

jtbandes


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

like image 45
Lou Franco Avatar answered Sep 21 '22 01:09

Lou Franco