NSIndexSet “-indexAtIndex:”?

后端 未结 4 1649
执念已碎
执念已碎 2020-12-18 20:57

This feels like a dumb question because it seems to me like my use case must be quite common.

Say I want to represent a sparse set of indexes with an NSIndexSet (whi

4条回答
  •  情书的邮戳
    2020-12-18 21:49

    Say I want to represent a sparse set of indexes with an NSIndexSet (which is of course what it's for).

    [my emphasis]

    Actually, no it's not. The documentation says this:

    You should not use index sets to store an arbitrary collection of integer values because index sets store indexes as sorted ranges.

    So if you are using it to store a sparse array of integers, it is quite inefficient. Also, the only way to get the nth index is to iterate from one end. You'd be better off using an array.

提交回复
热议问题