Question

What's the difference?

In my context, I need to be able to dynamically add to and remove objects. The user clicks on rows of a table that check on and off and thus add or remove the referenced object from the list.

A wild guess is that array has indexed items while set has no indexes?

Was it helpful?

Solution

An NSSet/NSMutableSet doesn't keep items in any particular order. An NSArray/NSMutableArray does store the items in a particular order. If you're building a table view, you should definitely use an array as your data source of choice.

OTHER TIPS

Also, NSMutableSet makes sure that all objects are unique.

NSMutableArray goes well with UITableView since elements have index, so you can return [array count] to get number of table rows, or [array objectAtIndex:rowNumber] to easily associate element with row.

Also, according to the documentation, testing for object membership is faster with NSSets.

You can use sets as an alternative to arrays when the order of elements isn’t important and performance in testing whether an object is contained in the set is a consideration—while arrays are ordered, testing for membership is slower than with sets.

Well there are 3 main differences. 1) Sets are unordered 2)Don't have an index & 3)Cannot have duplicate values where Arrays are ordered, indexed & can store duplicate values.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top