The final word on NSStrings: Mutable and Immutable

后端 未结 6 624
忘掉有多难
忘掉有多难 2020-12-16 23:14

I\'ve read in several books... and online... about immutable and mutable strings. They claim \"immutable strings\" can\'t be changed. (But they never define \"change\".)

6条回答
  •  一向
    一向 (楼主)
    2020-12-17 00:17

    NSString cannot be edited, every time you assign a string value to NSString object it will orphan the old string object and re-create the new string object. That is an expensive operation if you are dealing with large string buffer. If you are dealing with large string buffer then use NSMutableString for optimum performance. This is similar to string vs stringBuilder in .net.

提交回复
热议问题