【发布时间】:2017-12-30 15:12:43
【问题描述】:
我已经尝试了我能想到的所有排列方式,并阅读了各种关于 Swift #selectors 的文档,但我没有得到任何结果。代码如下:
class AFSelectionState: GKComponent {
let clearSelectionIndicator: (Set<Int>?) -> Void
let setSelectionIndicator: (Set<Int>) -> Void
init(setSelectionIndicator: @escaping (Set<Int>) -> Void, clearSelectionIndicator: @escaping (Set<Int>?) -> Void) {
self.clearSelectionIndicator = clearSelectionIndicator
self.setSelectionIndicator = setSelectionIndicator
}
}
class GameScene: SKScene, SKViewDelegate {
var selectionState: AFSelectionState!
override func sceneDidLoad() {
...
/****************** Compiler errors coming up ****************
**
** Tried #selector(setSelectionIndicator_(_:))
** Got "Cannot convert value of type 'Selector' to expected
** argument type '(Set<Int>) -> Void'"
** From what I've read, the above should be working, but you know
** how it is when people say "should".
**
** Tried #selector(setSelectionIndicator_(_:) -> ())
** Got "Expected type before '->'".
**
** Tried all sorts of other stuff. There's something about
** selectors that I'm missing.
**
*********************** Et cetera! *************************/
selectionState = AFSelectionState(
setSelectionIndicator: #selector(setSelectionIndicator_(_:)),
clearSelectionIndicator: #selector(clearSelectionIndicator_(_:))
)
...
}
}
extension GameScene {
@objc func setSelectionIndicator_(_ selectedIndexes: Set<Int>) -> Void {
...
}
@objc func clearSelectionIndicator_(_ indexes: Set<Int>?) -> Void {
...
}
}
【问题讨论】:
标签: swift syntax compiler-errors selector