Can someone please explain what the major differences there are between Tuples and Dictionaries are and when to use which in Swift?
In Named tuple we assign individual names to each elements.
Define it like:
let nameAndAge = (name:"Midhun", age:7)
Access the values like:
nameAndAge.name
nameAndAge.age
In unnamed tuple we don't specify the name for it's elements.
Define it like:
let nameAndAge = ("Midhun", 7)
Access the values like:
nameAndAge.0
nameAndAge.1
or
let (theName, thAge) = nameAndAge
theName
thAge
Tuples enable you to create and pass around groupings of values. You can use a tuple to return multiple values from a function as a single compound value.
You can check more about Tuple in Swift Programming Language
A dictionary is a container that stores multiple values of the same type. Each value is associated with a unique key, which acts as an identifier for that value within the dictionary
You can check more about Dictionary in Swift CollectionTypes