How to use Sets in Swift?
Set are basically a collection of items that aren’t ordered but are unique. Let's go over different operations/functions that Swift has when it comes to Sets. Creating a Set Initialize an empty set Sets in swift are of a generic nature so they can hold any type if it conforms to Hashable Protocol. For the simplicity of this article, we will use String and Int. var fruits = Set<String>() Initialize a Set with elements We can also initialize a set with some default elements. var fruits:Set<String> = ["apple","mango","guava"] Initialize a Set with a capacity We can set a space pre-allocated for minimum number/capacity var fruits = Set<String>(minimumCapacity: 2) Inspecting a set Check for empty Since Set conforms to Collection Protocol we can use a check for isEmpty. var fruits = Set<String>() fruits.isEmpty //true Count We can easily get the number of elements in our Set by accessing the count property. var fruits:Set...