我使用此代码创建了一个按钮类
http://nathandemick.com/programming/tutorial/2014/09/23/buttons-sprite-kit-using-swift.html
但是action变量没有参数 如果我更改 init 和操作
var action: (id: Int) -> Void
之后我无法执行touchesEnded方法中的函数
func test(){
println("test");
}
func testTwo(id: Int){
println("testTwo");
}
var action: () -> Void;
action = test
action() // prints test
var actionTwo: (id: Int) -> Void;
actionTwo = testTwo
// This work
actionTwo(id: 9); // prints testTwo
// But I want this to work
actionTwo();
最佳答案
您需要为您的函数提供一个定义,使整数参数成为可选的。
func testTwo(id: Int? = nil) {
print("something")
}
关于swift - 在 swift 中将带有参数的函数分配给变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31086544/