What is the purpose of having both NSMutableString and NSString?

前端 未结 4 1751
不知归路
不知归路 2020-12-09 23:45

Why does Objective C provide both class NSString and subclass NSMutableString rather than just provide NSMutableString? Isn\'t a NSString equivalent to \"const NSMutableStr

4条回答
  •  清歌不尽
    2020-12-09 23:50

    I would say the general rule is "don't use a class whose purpose is to provide functionality you don't need". If you need to change the contents of a string directly, use NSMutableString. If not, use NSString. In terms of size and how much heap space they take up, the classes themselves should be pretty similar.

提交回复
热议问题