Swift Tuples
Tuple is something that allows us to group together related pieces of data that have different data types and its as convenient as a simple dictionary but it gives us the flexibility of holding different data types and it’s not as high effort as creating a struct or a class.
import Foundationlet touple1 = ("Nadia" , 7)print(touple1.0)//this prints Nadia________________________________________________________Even though this format is short but it's not preferred.Instead we the following format._________________________________________________________let touple2 = (name : "Nadia" , faveNum : 7)print(touple2.name)//this also prints Nadia
There is also another way for creating tuples.
touple3: (name : String , faveNum: Int)//creates an emptytoupletouple3.name = "Nadia"touple3.faveNum = 7touple3 = (name : "Nadia" , faveNum: 7)
Conclusion
With tuples we are able to organize related pieces of data that are relatively small and we are able to create this really quickly pretty much on the fly.