您好,我把Swift编程语言书中的一些代码放到了一个游乐场上,我得到了以下错误消息。('(Int) -> Int' is not convertible to 'Int')这是怎么回事?感谢你的帮助
func stepForward (input: Int) -> Int {
return input + 1
}
func stepBackward (input: Int) -> Int {
return input - 1
}
func chooseStepFunction (backwards: Bool) -> Int {
return backwards ? stepBackward : stepForward
}发布于 2015-02-27 08:34:18
当chooseStepFunction期望返回一个Int时,您返回的是一个函数。您需要将返回类型从Int更改为(Int) -> Int
func chooseStepFunction (backwards: Bool) -> (Int) -> Int {
return backwards ? stepBackward : stepForward
}发布于 2015-02-27 08:34:28
当您尝试返回一个函数时,它应该是
func chooseStepFunction(backwards: Bool) -> (Int) -> Int {
return backwards ? stepBackward : stepForward
}chooseStepFunction返回一个函数,该函数接受一个整数,并返回一个整数。
https://stackoverflow.com/questions/28755456
复制相似问题