我想在函数声明中将函数作为变量,然后在声明的函数中调用该变量。如何使用Swift
伪代码:
let something = 0
func one() {
print("one")
}
// Definition
func two( funcVariable: Void, number: Int) {
print("(number)")
funcVariable() // here I want to call variable function
}
// Call
two(funcVariable: one(), number: somethhing)
怎么做
感谢示例代码。
以下是您的操作方法:
let something = 0
func one() {
print("one")
}
// Definition
func two(funcVariable: () -> Void, number: Int) {
print("(number)")
funcVariable()
}
// Call
two(funcVariable: one, number: something)