私は考えることができるすべての並べ替えを試してみました。Swift #selectors
に関するすべての種類のドキュメントを読んでいますが、私はどこにもいません。ここでは、コードです:簡単なSwiftの#selectorをコンパイルできない
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 {
...
}
}