Set vs Array

The main difference is that NSArray is an ordered collection and NSSet is an unordered list of unique elements.

Set
  • Primarily access items by comparison   
E.g    let ingredients = [“Tea Powder”, “Sugar”, “Hot Water”, “Milk”, "Cardamom"]
          if ingredients.contains(“Cardamom”) {
print(“It is Cardamom Tea”)
}
  • unordered
  • does not allow duplicates
Array

  • Can access items by Index
  • Ordered
  • Allow duplicates

No comments:

Post a Comment