A mutable object can be changed after it's created, and an immutable object can't.
In Objective-C, mutable types, like NSMutableArray, can be modified:
Immutable types, like NSArray, can't be changed:
Strings are the same way. Use NSMutableString for mutable strings, and NSString for immutable strings:
Mutable objects are nice because you can make changes in-place, without allocating a new object. But be careful—whenever you make an in-place change to an object, all references to that object will now reflect the change.
Interview coming up?
Get the free 7-day email crash course. You'll learn how to think algorithmically, so you can break down tricky coding interview questions.
No prior computer science training necessary—we'll get you up to speed quickly, skipping all the overly academic stuff.
No spam. One-click unsubscribe whenever.
You're in! Head over to your email inbox right now to read day one!