-2

What is the difference between String and NSString?

  • There's no reason for you to use NSMutableString, so don't. This is Swift, not Objective-C. Always use the Foundation bridged type, not the Objective-C type. – matt Jul 13 '22 at 16:07

1 Answers1

2

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.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • I'll add that the way they count "by default" there characters are different: UTF16 vs UTF8. So `aString.count` might be different from `aNS(Mutable)String.length`, which is a mistake often done... – Larme Jul 19 '22 at 20:29