NSMutableArray vs NSArray which is better

后端 未结 6 1601
再見小時候
再見小時候 2021-02-05 18:11

This is a bit of a silly question, but if I want to add an object to an array I can do it with both NSMutableArray and NSArray, which should I use?

6条回答
  •  一生所求
    2021-02-05 18:22

    Use NSMutableArray, that is what it is there for. If I was looking at code and I saw NSArray I would expect it's collection to stay constant forever, whereas if I see NSMuteableArray I know that the collection is destined to change.

    It might not sound like much right now, but as your project grows and as you spend more time on it you will see the value of this eventually.

提交回复
热议问题