Difference between Array/Set/Dictionary and Tuples
Array has ordered collection of value.Set is unordered collection of value.Dictionary are unordered collection of key value association.
class ViewController: UIViewController {
var arrray :[String] = [“Apple”,”Bananana”,”Orange”,”Orange”]
var set :Set<String> = [“Apple”,”Bananana”,”Orange”,”Orange”]
override func viewDidLoad() {
super.viewDidLoad()
print(arrray) //Print[“Apple”, “Bananana”, “Orange”,”Orange”]
print(set) //[“Orange”, “Apple”, “Bananana”]
// Do any additional setup after loading the view.
}
}
Above example clear Array is ordered collection while Set is unordered Collection with unique value.
Dictionary
A dictionary stores associations between keys of the same type and values of the same type in a collection with no defined ordering.
var namesOfIntegers = [Int: String]()
namesOfIntegers = [1:”One”,2:”Two”]
print(namesOfIntegers) //[1: “One”, 2: “Two”]
Tuple
Tuple is group of different value represent as one.
var tuple = (0,”varun”)
print(tuple) //(0, “varun”)
print(tuple.1) //varun
Note:Tuple is value type it means when you intialize value tuple with another acctually its make another copy .For more detail of value based you can go through https://medium.com/@varun.singhal78/structure-class-enum-caseiterable-in-swift-e3451636bbe5