The final word on NSStrings: Mutable and Immutable

后端 未结 6 621
忘掉有多难
忘掉有多难 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:11

    The answer is - none. Immutable means it cannot be changed into anything different than the original string. Every character stays the same, the length cannot change, etc. Once it's defined you cannot change anything about that string. If you want to make it longer or shorter or change any of the characters, you need to make a new string (or use a NSMutableString to begin with).

提交回复
热议问题