What is the difference between String and NSMutableString?
var firstString: String = "A"
var first2String: String = ""
first2String = firstString
firstString = "B"
var firstString: NSMutableString = "A"
var first2NSString: NSMutableString = ""
first2NSString = firstString
firstString = "B"
CodePudding user response:
String
is a Swift native type, and uses value semantics.
NSMutableString
is a Foundation Class object that is "toll-free-bridged" with the Swift String
type. As a Class object it uses reference semantics.
The NSMutableString
class has a few methods that the Swift String type does not.
CodePudding user response:
This is related to the reference and value type