【发布时间】:2018-01-04 19:35:18
【问题描述】:
我的 Swift 代码如下所示:
class SystemClass {
public init() {}
func setXYZ(xyz: Float32) {
// do something
}
}
let callME: class = class()
class class {
public init() {}
func functionXYZ() {
Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(SystemClass().setXYZ(xyz: 1.0)), userInfo: nil, repeats: true) // error code
}
}
callME.functionXYZ()
我想调用“functionXYZ”,这已经可以正常工作,但调用 setXYZ 函数会导致错误,因为选择器失败。
如何编辑选择器:
#selector(SystemClass().setXYZ(xyz: 1.0))
用给定的参数调用setXYZ函数?
【问题讨论】:
-
你不能这样传递参数,选择器等待签名,而不是参数。您可以改用
userInfo。 -
请不要回滚有用的编辑。不要使用不相关的标签。不要在标题中添加标签和不必要的评论。我还修复了其他格式。无需撤消所有这些有用且适当的更改。