SEL in Swift

在我们使用Objective-c 时经常使用SEL来执行某些操作。那么在Swift中如何使用呢?在Swift中是用 #selector表示,#selector(MyViewController.tappedButton(sender:))

例如:

  • Objective-c
UIButton *myButton = [UIButton new];
[myButton addTarget:self action:@selector(clickmyButton:) forControlEvents:UIControlEventTouchUpInside];
  • Swift
let action = #selector(MyViewController.clickmyButton)
myButton.addTarget(self, action: action, forControlEvents: .touchUpInside)

你可能感兴趣的:(SEL in Swift)