通过下标访问元组 [英] Access tuples by subscript
本文介绍了通过下标访问元组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有这个代码:
let tuples = ("1", 2, "3", "4", "5", "6", "7", false)
func tableView(tableView:NSTableView, viewForTableColumn tableColumn:NSTableColumn?, row:Int) -> NSView?
{
let valueForView = tuples[row]
}
有没有办法通过下标访问元组?
Is there any way to access tuples by subscript?
推荐答案
您想要的东西在元组中是不可能的,如果您不想稍后强制转换所有内容,那么您唯一的选择就是结构体或类.struct 似乎是一个更好的选择 :)
What you want is not possible with tuples and if you dont want to cast everything later-on your only option is struct or class. struct seems like a better choise :)
struct MyStruct {
let opt1 = 0
let opt2 = 0
let opt3 = 0
...
let boolThing = false
}
这篇关于通过下标访问元组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文