user891268 user891268 - 5 months ago 60
Objective-C Question

what is difference between mutable and immutable

what is difference mutable and immutable


NSString and NSMutableString.

NSArray and NSMutableArray.

NSDictionary and NSMutableDictionary.

What is difference between mutable object and the other object[which i guess immutable]

@thanks in advance.


A mutable object can be mutated or changed. An immutable object cannot. For example, while you can add or remove objects from an NSMutableArray, you cannot do either with an NSArray.

Mutable objects can have elements changed, added to, or removed, which cannot be achieved with immutable objects. Immutable objects are stuck with whatever input you gave them in their [[object alloc] initWith...] initializer.

The advantages of your mutable objects is obvious, but they should only be used when necessary (which is a lot less often than you think) as they take up more memory than immutable objects.