// *** 以前 ***
// 方法用字符串命名;拼写错误或重命名只有在点击按钮时才被发现,应用随即崩溃
button.addTarget(self, action: "buttonTapped:",
forControlEvents: .TouchUpInside)
let timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self,
selector: "tick", userInfo: nil, repeats: true)
// *** 在 2.2 版本中 ***
button.addTarget(self, action: #selector(buttonTapped(_:)),
forControlEvents: .TouchUpInside)
let timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self,
selector: #selector(tick), userInfo: nil, repeats: true)
// 编译器检查此类方法是否存在,且对 Objective-C 可见
func buttonTapped(sender: AnyObject) { }
func tick() { }
// 两个方法同名时,按类型选出其中一个
let action = #selector(((tick) as () -> Void))