01 調用 有參數名
// 無參數
@objc func callMe() {
}
// 一個參數
@objc func callMeWithParam(obj: AnyObject!) {
}
// 多個參數
@objc func turn(by angle: Int, speed: Float) {
}
func selectors() -> [Selector] {
let someMethod = #selector(callMe)
let anotherMethod = #selector(callMeWithParam(obj:))
let method = #selector(turn(by:speed:))
return [someMethod, anotherMethod, method]
}
打印selectors的結果
[callMe, callMeWithParamWithObj:, turnBy:speed:]
02 調用 無參數名
func otherSelectors() -> [Selector] {
let someMethod = #selector(callMe)
let anotherMethod = #selector(callMeWithParam)
let method = #selector(turn)
return [someMethod, anotherMethod, method]
}
打印selectors的結果
[callMe, callMeWithParamWithObj:, turnBy:speed:]
03 調用 加 函數類型
@objc func commonFunc() {
}
@objc func commonFunc(input: Int) -> Int {
return input
}
func sameNameSelectors() -> [Selector] {
let method1 = #selector(commonFunc as ()->())
let method2 = #selector(commonFunc as (Int)->Int)
return [method1, method2]
}
打印selectors的結果
[commonFunc, commonFuncWithInput:]