I am new Objective-c programming. I am reading about NSSting
and NSMutableString
. NSString
is basically immutable string whereas NSMutableString
is mutable as its name implies. That's fine But I want to know apart from mutable and immutable, why NSString
is not deprecated still if I can perform all operation of NSString
with NSMutableString
. Can anyone clear to me??
Asked
Active
Viewed 93 times
0

Ashok Kumar
- 21
- 4
-
I believe you'r question is already answered check [this](http://stackoverflow.com/questions/16460779/what-is-actual-difference-between-nsstring-and-nsmutable-string-in-objective-c-w) & [this](http://stackoverflow.com/questions/1749571/what-is-the-purpose-of-having-both-nsmutablestring-and-nsstring) – Mahbub Ahmed Apr 09 '17 at 14:57
-
Thanks @MahbubAhmed and @gema for response. It is really helpful. So please let me correct, what I understood basically `NSString` performance wise (from compiler perspective it remove the extra conditioning for value check and overhead) and memory wise `NSString` always create new memory on new assigning value as explained [link](http://stackoverflow.com/questions/1749571/what-is-the-purpose-of-having-both-nsmutablestring-and-nsstring). – Ashok Kumar Apr 09 '17 at 15:14
1 Answers
0
It's all about performance in case of memory overhead. From Apple site
Performance is also a reason for immutable versions of objects representing things such as strings and dictionaries. Mutable objects for basic entities such as strings and dictionaries bring some overhead with them. Because they must dynamically manage a changeable backing store—allocating and deallocating chunks of memory as needed—mutable objects can be less efficient than their immutable counterparts.
So on my opinion, the immutable version which is NSString, is important. We always have to keep in mind about our code performance and efficiency.

Gema Megantara
- 520
- 6
- 15