Skip to content

Commit 75d607d

Browse files
committed
Use the Selector syntax sugar
1 parent 96aff56 commit 75d607d

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

Example/Example/CustomizedTokenViewController.swift

Lines changed: 9 additions & 1 deletion
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: .dismiss)
5454
cancelBarButton.tintColor = UIColor.whiteColor()
5555
navigationItem.rightBarButtonItem = cancelBarButton
5656

@@ -106,3 +106,11 @@ class CustomizedTokenViewController: UIViewController, ICTokenFieldDelegate {
106106
}
107107

108108
}
109+
110+
111+
////////////////////////////////////////////////////////////////////////////////
112+
113+
114+
private extension Selector {
115+
static let dismiss = #selector(CustomizedTokenViewController.dismiss(_:))
116+
}

Example/Example/ExampleViewController.swift

Lines changed: 9 additions & 1 deletion
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: .showStoryboard, forControlEvents: .TouchUpInside)
4343
return _button
4444
}()
4545

@@ -133,3 +133,11 @@ class ExampleViewController: UITableViewController {
133133
}
134134

135135
}
136+
137+
138+
////////////////////////////////////////////////////////////////////////////////
139+
140+
141+
private extension Selector {
142+
static let showStoryboard = #selector(ExampleViewController.showStoryboard(_:))
143+
}

Source/KeyboardDismissTextField/ICKeyboardDismissTextField.swift

Lines changed: 9 additions & 1 deletion
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: .dismiss, forControlEvents: .TouchUpInside)
3636
inputAccessoryView = keyboardAccessoryView
3737
}
3838
}
@@ -74,3 +74,11 @@ public class ICKeyboardDismissTextField: UITextField {
7474
}
7575

7676
}
77+
78+
79+
////////////////////////////////////////////////////////////////////////////////
80+
81+
82+
private extension Selector {
83+
static let dismiss = #selector(ICKeyboardDismissTextField.dismiss(_:))
84+
}

Source/TokenField/ICTokenField.swift

Lines changed: 11 additions & 2 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: .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: .handleTapGesture)
210210
}()
211211

212212
// MARK: - Initialization
@@ -454,3 +454,12 @@ public class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDele
454454
}
455455

456456
}
457+
458+
459+
////////////////////////////////////////////////////////////////////////////////
460+
461+
462+
private extension Selector {
463+
static let togglePlaceholderIfNeeded = #selector(ICTokenField.togglePlaceholderIfNeeded(_:))
464+
static let handleTapGesture = #selector(ICTokenField.handleTapGesture(_:))
465+
}

0 commit comments

Comments
 (0)