Swift Tuple index using a variable as the index?

前端 未结 5 906
灰色年华
灰色年华 2021-01-21 08:31

Swift Tuple index using a variable as the index? Anyone know if it is possible to use a variable as the index for a Swift tuple index. I wish to select and item from a tuple usi

5条回答
  •  遇见更好的自我
    2021-01-21 09:26

    As long as tuple index is just default name, and you can provide your own names

    let testTuple = (first: 1, second: 2.0)
    let first: Int = testTuple.first
    let second: Double = testTuple.second
    

    you can not use variable as index. Pretty close question "can I use KVC for tuple?", and answer - you can't

提交回复
热议问题