# Problem with tuples

**URL:** <https://forums.kodeco.com/t/problem-with-tuples/26333>\
**Category:** Swift Apprentice\
**Created:** [February 17, 2017, 10:24pm UTC](https://forums.kodeco.com/t/problem-with-tuples/26333 "2017-02-17T22:24:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaclawiciel](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jaclawiciel/32/53999_2.png) [@jaclawiciel](https://forums.kodeco.com/u/jaclawiciel)\
**Post date:** [February 17, 2017, 10:24pm UTC](https://forums.kodeco.com/t/problem-with-tuples/26333/1 "2017-02-17T22:24:15Z")

</div>

![](https://raywenderlich-com-v3-forums.s3.amazonaws.com/original/3X/b/1/b1e95636a03c4883edb47d16289d0cd7a66b9340.png)I practice tuples mini-exercises in Chapter 3 about types and operations.

I don’t think that it should behave like that but if I make a mistake somewhere please correct me.

When I declare a tuple like so:  
let dateWithTemperature1: (Int, Int, Int, Double) = (day: 17, month: 2, year: 2017, averageTemp: 7.0)  
and I try to get access to items of dateWithTemperature1 tuple I can’t refer to them by their names.  
When I declare a tuple with types set by type inference:  
let dateWithTemperature2 = (day: 17, month: 2, year: 2017, averageTemp: 7.0)  
I can easily get access to data by numbers and by names.

What do you think of that guys?

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [July 17, 2017, 5:08pm UTC](https://forums.kodeco.com/t/problem-with-tuples/26333/2 "2017-07-17T17:08:03Z")

</div>

In order for the above code to work properly, this is how you should declare the tuple in this case:

`let dateWithTemperature1: (day: Int, month: Int, year: Int, averageTemp: Double) = (17, 2, 2017, 7.0)`

As you can see, each and every tuple label appear next to its corresponding and associated tuple type in the tuple’s definition, declaration and prototype. Now you can access the tuple’s values as you would normally do with type inference after all for sure and for good indeed:

`
dateWithTemperature1.day
dateWithTemperature1.month
dateWithTemperature1.year
dateWithTemperature1.averageTemp
`

Please let me know if you have any questions regarding the whole thing. Thanks! :]

---

<div class="post-metadata">

**Author:** ![osvimong](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/osvimong/32/81494_2.png) [@osvimong](https://forums.kodeco.com/u/osvimong)\
**Post date:** [November 3, 2019, 6:21pm UTC](https://forums.kodeco.com/t/problem-with-tuples/26333/3 "2019-11-03T18:21:52Z")

</div>

Thanks, i write two solution for this exercise:

let dayWithTemperature: (month:Int , day:Int, year:Int , temperature:Double) = (17,10,1993,25.7)

dayWithTemperature.day  
dayWithTemperature.month  
dayWithTemperature.temperature  
dayWithTemperature.year

let giornoConTemperatura = (mese:17,giorno:10,anno:19,temperatura:106.6)  
giornoConTemperatura.mese  
giornoConTemperatura.giorno  
giornoConTemperatura.anno  
giornoConTemperatura.temperatura

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [January 11, 2020, 3:47pm UTC](https://forums.kodeco.com/t/problem-with-tuples/26333/4 "2020-01-11T15:47:41Z")

</div>

@osvimong Thank you for sharing your solution - much appreciated! :]
