cocoanssetnsindexset

What's the difference between NSIndexSet and NSSet?


I'm a bit new to Cocoa and I was reading about NSIndexSet. Why is it necessary? It seems to me that NSIndexSet is nothing but a NSSet of integers, is that right? What's the purpose of creating a separate collection alltogether?


Solution

  • There are a couple reasons:

    1. NSIndexSet stores unsigned integer primitive types, whereas NSSet stores objects.
    2. NSIndexSet is optimized for storing unsigned integers, specifically a set of integers into another data structure like an NSArray.