【发布时间】:2021-02-14 03:50:08
【问题描述】:
是否可以创建我自己的可以选择的对象?例如在一个函数中:
struct MyCustomType {
let id = 178
let reg = Expression<String?>(“reg”)
}
func runThis(enter: MyCustomType)
{
print(enter)
}
基本上在调用 runThis 函数时,我想选择 id 或 reg。不是它的价值,而是像这样从 Id 和 reg 中选择:
runThis(enter: id)
//print 178
【问题讨论】:
-
基本上你想使用通用值?
-
基本上我想选择进入我的函数而不是通用的。因此,例如,您只能选择(这个,那个,然后)。一个可以是日期,一个是 Int,一个是 String。
-
你回答你自己的问题,你想选择通用
标签: swift function class object struct