When is it better to use an NSSet over an NSArray?

前端 未结 11 1570
-上瘾入骨i
-上瘾入骨i 2020-12-12 10:27

I have used NSSets many times in my apps, but I have never created one myself.

When is it better to use an NSSet as opposed to an NSArray and why?

11条回答
  •  独厮守ぢ
    2020-12-12 11:00

    When the order of the items in the collection is not important, sets offer better performance for finding items in the collection.

    The reason is that a set uses hash values to find items (like a dictionary) while an array has to iterate over its entire contents to find a particular object.

提交回复
热议问题