Swift Tuples

Nadia Ahmadian
Nerd For Tech
Published in
1 min readAug 6, 2021

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.

--

--

Nerd For Tech
Nerd For Tech

Published in Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.

Nadia Ahmadian
Nadia Ahmadian

Written by Nadia Ahmadian

a crazy gemini who believes in magic, aliens and impossible dreams and converts coffee into iOS apps and soon web apps

No responses yet