Swift array.capacity vs array.count

后端 未结 3 989
我在风中等你
我在风中等你 2020-12-10 06:39

I understand the array.count ( the number of elements in the array ). count is useful to iterate over the array\'s elements. I sort of get the gist of array.capacit

3条回答
  •  长情又很酷
    2020-12-10 06:56

    What is the use of an array capacity

    Basically, the array capacity has no external use. It is there for Swift's internal use. If you know that you will be allocating 100 objects to this array, you could set the capacity in advance as you create the array, and I have seen some people do that in their code; but there is no particular need to do so and no particular gain in doing so. You've looked under the hood and seen something you didn't really need to see. Now that you've seen, you can forget about it.

提交回复
热议问题