If we create an Objective-C string literal @"mutable_example", then actually we create constant string. The compiler will put this string in the constants section of the binary, if we will try to modify it, it will cause a segmentation fault.
If we create a new string and copying string can make a program very slow, however this is one of the reasons Java code has a reputation for being slow; Java's String class is immutable, and since it is declared final you can't use Cocoa's solution to the problem, a mutable subclass.
The NSString object is an immutable string, it has a subclass called "NSMutableString", because the mutable version is a subclass, it can be used anywhere that the immutable version can. It implements all of the same methods.
The distinction between mutable and immutable objects is most apparent in the implementation of the -copy method. When you send a -copy message to an immutable object, you often get the same object back, because you cannot modify either "copy" they can never become different from each other.
Liked By
Write Answer
Define Mutability
Join MindStick Community
You have need login or register for voting of answers or question.
Tarun Kumar
02-Nov-2015If we create an Objective-C string literal @"mutable_example", then actually we create constant string. The compiler will put this string in the constants section of the binary, if we will try to modify it, it will cause a segmentation fault.
If we create a new string and copying string can make a program very slow, however this is one of the reasons Java code has a reputation for being slow; Java's String class is immutable, and since it is declared final you can't use Cocoa's solution to the problem, a mutable subclass.
The NSString object is an immutable string, it has a subclass called "NSMutableString", because the mutable version is a subclass, it can be used anywhere that the immutable version can. It implements all of the same methods.
The distinction between mutable and immutable objects is most apparent in the implementation of the -copy method. When you send a -copy message to an immutable object, you often get the same object back, because you cannot modify either "copy" they can never become different from each other.