Skip to content

Commit 94855ba

Browse files
committed
Use #selector to replace string literal for Objective-C selectors
1 parent 6c9a826 commit 94855ba

4 files changed

Lines changed: 16 additions & 16 deletions

File tree

Example/Example/CustomizedTokenViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class CustomizedTokenViewController: UIViewController, ICTokenFieldDelegate {
5050
navigationController?.navigationBar.translucent = false
5151
navigationController?.navigationBar.barStyle = .Black
5252

53-
let cancelBarButton = UIBarButtonItem(barButtonSystemItem: .Cancel, target: self, action: Selector("dismiss:"))
53+
let cancelBarButton = UIBarButtonItem(barButtonSystemItem: .Cancel, target: self, action: #selector(dismiss(_:)))
5454
cancelBarButton.tintColor = UIColor.whiteColor()
5555
navigationItem.rightBarButtonItem = cancelBarButton
5656

@@ -95,7 +95,7 @@ class CustomizedTokenViewController: UIViewController, ICTokenFieldDelegate {
9595

9696
// MARK: - UIResponder Callbacks
9797

98-
@IBAction private func dismiss(sender: UIBarButtonItem) {
98+
@objc private func dismiss(sender: UIBarButtonItem) {
9999
presentingViewController?.dismissViewControllerAnimated(true, completion: nil)
100100
}
101101

Example/Example/ExampleViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ExampleViewController: UITableViewController {
3939
let _button = UIButton(type: .System)
4040
_button.frame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 88)
4141
_button.setTitle("Storyboard", forState: .Normal)
42-
_button.addTarget(self, action: Selector("showStoryboard:"), forControlEvents: .TouchUpInside)
42+
_button.addTarget(self, action: #selector(showStoryboard(_:)), forControlEvents: .TouchUpInside)
4343
return _button
4444
}()
4545

@@ -125,7 +125,7 @@ class ExampleViewController: UITableViewController {
125125

126126
// MARK: - UIResponder Callbacks
127127

128-
@IBAction private func showStoryboard(sender: UIButton) {
128+
@objc private func showStoryboard(sender: UIButton) {
129129
if let controller = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()).instantiateInitialViewController() {
130130
controller.modalTransitionStyle = .FlipHorizontal
131131
presentViewController(controller, animated: true, completion: nil)

Source/KeyboardDismissTextField/ICKeyboardDismissTextField.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class ICKeyboardDismissTextField: UITextField {
3232
@IBOutlet public var keyboardAccessoryView: ICKeyboardDismissAccessoryView! {
3333
didSet {
3434
if UI_USER_INTERFACE_IDIOM() != .Phone { return }
35-
keyboardAccessoryView.dismissButton.addTarget(self, action: Selector("dismiss:"), forControlEvents: .TouchUpInside)
35+
keyboardAccessoryView.dismissButton.addTarget(self, action: #selector(dismiss(_:)), forControlEvents: .TouchUpInside)
3636
inputAccessoryView = keyboardAccessoryView
3737
}
3838
}
@@ -58,6 +58,13 @@ public class ICKeyboardDismissTextField: UITextField {
5858
return super.becomeFirstResponder()
5959
}
6060

61+
@objc private func dismiss(sender: UIButton) {
62+
resignFirstResponder()
63+
UIView.animateWithDuration(0.3) {
64+
self.keyboardAccessoryView.alpha = 0
65+
}
66+
}
67+
6168
// MARK: - Private Methods
6269

6370
private func setUpAccessoryView() {
@@ -66,11 +73,4 @@ public class ICKeyboardDismissTextField: UITextField {
6673
}
6774
}
6875

69-
@IBAction private func dismiss(sender: UIButton) {
70-
resignFirstResponder()
71-
UIView.animateWithDuration(0.3) {
72-
self.keyboardAccessoryView.alpha = 0
73-
}
74-
}
75-
7676
}

Source/TokenField/ICTokenField.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDele
172172
_textField.returnKeyType = .Search
173173
_textField.delegate = self
174174
_textField.backspaceDelegate = self
175-
_textField.addTarget(self, action: Selector("togglePlaceholderIfNeeded:"), forControlEvents: .AllEditingEvents)
175+
_textField.addTarget(self, action: #selector(togglePlaceholderIfNeeded(_:)), forControlEvents: .AllEditingEvents)
176176
return _textField
177177
}()
178178

@@ -206,7 +206,7 @@ public class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDele
206206
}()
207207

208208
private lazy var tapGestureRecognizer: UITapGestureRecognizer = {
209-
UITapGestureRecognizer(target: self, action: Selector("handleTapGesture:"))
209+
UITapGestureRecognizer(target: self, action: #selector(handleTapGesture(_:)))
210210
}()
211211

212212
// MARK: - Initialization
@@ -336,12 +336,12 @@ public class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDele
336336

337337
// MARK: - UIResponder Callbacks
338338

339-
@IBAction private func togglePlaceholderIfNeeded(sender: UITextField? = nil) {
339+
@objc private func togglePlaceholderIfNeeded(sender: UITextField? = nil) {
340340
let showsPlaceholder = tokens.isEmpty && (inputTextField.text?.isEmpty ?? true)
341341
placeholderLabel.hidden = !showsPlaceholder
342342
}
343343

344-
@IBAction private func handleTapGesture(sender: UITapGestureRecognizer) {
344+
@objc private func handleTapGesture(sender: UITapGestureRecognizer) {
345345
if !isFirstResponder() {
346346
inputTextField.becomeFirstResponder()
347347
}

0 commit comments

Comments
 (0)