波斯汪
Swift由于并非基于消息机制,所以本身没有selector这个十分灵活的机制,但是可以使用Cocoa Framework中所留下的一些selector,比如:<pre class="brush:objc; toolbar: true; auto-links: false;">import UIKitclass MyViewController: UIViewController {let myButton = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 50))init(nibName nibNameOrNil: String!, bundle nibBundleOrNil: NSBundle!) {super.init(nibName: nibName, bundle: nibBundle) myButton.targetForAction("tappedButton:", withSender: self)}func tappedButton(sender: UIButton!) { println("tapped button")} }</pre>上述代码,"tappedButton:"就是一个selector,呵呵。