Here is an explanation of when to use NSArray vs NSSet in Objective-C:
NSArray
- Use NSArray when you need an ordered collection of objects and the order of the objects matters.
- NSArray allows duplicate objects.
- You can access objects in an NSArray by index.
- NSArray has methods to add, insert, and remove objects at specific indexes.
- NSArray conforms to the NSCopying protocol, so you can create copies of arrays.
NSSet
- Use NSSet when you need an unordered collection of unique objects and the order does not matter.
- NSSet does not allow duplicate objects. If you add an object that is already in the set, nothing happens.