Skip to content

Commit 43de68b

Browse files
committed
Update to Swift 3 finalized syntax
1 parent 214bc46 commit 43de68b

8 files changed

Lines changed: 27 additions & 27 deletions

Example/Example/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3131

3232
var window: UIWindow?
3333

34-
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
34+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
3535
window = UIWindow(frame: UIScreen.main.bounds)
3636
window?.backgroundColor = UIColor.white
3737
window?.rootViewController = UINavigationController(rootViewController: ExampleViewController())

Example/Example/CustomizedTokenField.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ extension ICTokenField {
6060
textField.font = UIFont.boldSystemFont(ofSize: 14)
6161

6262
attributedPlaceholder = NSAttributedString(
63-
string: String(self.dynamicType),
63+
string: String(describing: type(of: self)),
6464
attributes: [
6565
NSForegroundColorAttributeName: UIColor.white.withAlphaComponent(0.5),
6666
NSFontAttributeName: UIFont.boldSystemFont(ofSize: 14)

Example/Example/CustomizedTokenViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class CustomizedTokenViewController: UIViewController, ICTokenFieldDelegate {
3838
super.loadView()
3939
view.backgroundColor = UIColor.white
4040
textView.text = "[\n\n]";
41-
textView.font = UIFont.preferredFont(forTextStyle: UIFontTextStyleSubheadline)
41+
textView.font = UIFont.preferredFont(forTextStyle: .subheadline)
4242
textView.frame = view.bounds.insetBy(dx: 10, dy: 10)
4343
textView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
4444
view.addSubview(textView)
@@ -95,7 +95,7 @@ class CustomizedTokenViewController: UIViewController, ICTokenFieldDelegate {
9595

9696
// MARK: - UIResponder Callbacks
9797

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

Example/Example/ExampleViewController.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class ExampleViewController: UITableViewController {
5454

5555
override func loadView() {
5656
super.loadView()
57-
tableView.register(ExampleCell.self, forCellReuseIdentifier: NSStringFromClass(ExampleCell.self))
57+
tableView.register(ExampleCell.self, forCellReuseIdentifier: String(describing: ExampleCell.self))
5858
tableView.tableFooterView = flipButton
5959
tableView.tableFooterView?.isUserInteractionEnabled = true
6060
}
@@ -83,23 +83,24 @@ class ExampleViewController: UITableViewController {
8383
}
8484

8585
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
86-
let cell = tableView.dequeueReusableCell(withIdentifier: NSStringFromClass(ExampleCell.self), for: indexPath)
87-
switch types[(indexPath as NSIndexPath).section] {
86+
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ExampleCell.self), for: indexPath)
87+
88+
switch types[indexPath.section] {
8889
case let type as ICKeyboardDismissTextField.Type:
8990
let textField = type.init()
9091
textField.leftViewMode = .always
9192
textField.leftView = UIView(frame: CGRect(x: 0, y: 0, width: 15, height: 15))
92-
textField.placeholder = String(type)
93+
textField.placeholder = String(describing: type)
9394
(cell as? ExampleCell)?.showcase = textField
9495

9596
case let type as CustomizedTokenField.Type:
96-
cell.textLabel?.text = String(type)
97+
cell.textLabel?.text = String(describing: type)
9798
cell.accessoryType = .disclosureIndicator
9899

99100
case let type as ICTokenField.Type:
100101
let container = UIView(frame: cell.bounds)
101102
let tokenField = type.init()
102-
tokenField.placeholder = String(type)
103+
tokenField.placeholder = String(describing: type)
103104
tokenField.frame = container.bounds.insetBy(dx: 5, dy: 0)
104105
tokenField.autoresizingMask = [.flexibleWidth, .flexibleHeight]
105106
container.addSubview(tokenField)
@@ -114,18 +115,18 @@ class ExampleViewController: UITableViewController {
114115
// MARK: - UITableViewDelegate
115116

116117
override func tableView(_ tableView: UITableView, shouldHighlightRowAt indexPath: IndexPath) -> Bool {
117-
return types[(indexPath as NSIndexPath).section] == CustomizedTokenField.self
118+
return types[indexPath.section] == CustomizedTokenField.self
118119
}
119120

120121
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
121-
if types[(indexPath as NSIndexPath).section] == CustomizedTokenField.self {
122+
if types[indexPath.section] == CustomizedTokenField.self {
122123
present(UINavigationController(rootViewController: CustomizedTokenViewController()), animated: true, completion: nil)
123124
}
124125
}
125126

126127
// MARK: - UIResponder Callbacks
127128

128-
@objc private func showStoryboard(_ sender: UIButton) {
129+
@objc fileprivate func showStoryboard(_ sender: UIButton) {
129130
if let controller = UIStoryboard(name: "Main", bundle: Bundle.main).instantiateInitialViewController() {
130131
controller.modalTransitionStyle = .flipHorizontal
131132
present(controller, animated: true, completion: nil)

Source/KeyboardDismissTextField/ICKeyboardDismissAccessoryView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class ICKeyboardDismissAccessoryView: UIView {
4040
/// The button to dismiss keyboard.
4141
public private(set) lazy var dismissButton: UIButton = {
4242
let _button = UIButton()
43-
let resources = Bundle(for: self.dynamicType)
43+
let resources = Bundle(for: type(of: self))
4444
let icon = UIImage(named: "icook-iphone-button-hide-keyboard", in: resources, compatibleWith: nil)
4545
_button.setImage(icon, for: UIControlState())
4646
_button.backgroundColor = Constants.ButtonColor
@@ -86,7 +86,7 @@ public class ICKeyboardDismissAccessoryView: UIView {
8686

8787
// MARK: - NSKeyValueCoding
8888

89-
public override func setValue(_ value: AnyObject?, forUndefinedKey key: String) {
89+
public override func setValue(_ value: Any?, forKey key: String) {
9090
if let color = value as? UIColor, key == "buttonColor" {
9191
buttonColor = color
9292
}

Source/KeyboardDismissTextField/ICKeyboardDismissTextField.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class ICKeyboardDismissTextField: UITextField {
6262
return super.becomeFirstResponder()
6363
}
6464

65-
@objc private func dismiss(_ sender: UIButton) {
65+
@objc fileprivate func dismiss(_ sender: UIButton) {
6666
resignFirstResponder()
6767
UIView.animate(withDuration: 0.3) {
6868
self.keyboardAccessoryView.alpha = 0

Source/TokenField/ICInsetLabel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ICInsetLabel: UILabel {
4242
self.cornerRadius = cornerRadius
4343

4444
switch cornerRadius {
45-
case .constant(let radius) where radius > 0:
45+
case let .constant(radius) where radius > 0:
4646
layer.cornerRadius = radius
4747
fallthrough
4848
case .dynamic:

Source/TokenField/ICTokenField.swift

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDele
245245

246246
// MARK: - NSKeyValueCoding
247247

248-
public override func setValue(_ value: AnyObject?, forUndefinedKey key: String) {
248+
public override func setValue(_ value: Any?, forKey key: String) {
249249
switch value {
250250
case let image as UIImage? where key == "icon":
251251
icon = image
@@ -282,16 +282,15 @@ public class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDele
282282
_ = removeHighlightedToken() // as user starts typing when a token is focused
283283
inputTextField.showsCursor = true
284284

285-
guard
286-
let input = textField.text,
287-
let text: NSString = (input as NSString).replacingCharacters(in: range, with: string)
288-
else {
285+
guard let input = textField.text else {
289286
return true
290287
}
291288

292-
for delimiter in delimiters as [NSString] {
293-
let index = text.length - delimiter.length
294-
if 0 < index && text.substring(from: index) == delimiter {
289+
let text = (input as NSString).replacingCharacters(in: range, with: string)
290+
291+
for delimiter in delimiters {
292+
if text.hasSuffix(delimiter) {
293+
let index = text.index(text.endIndex, offsetBy: -delimiter.characters.count)
295294
let newToken = text.substring(to: index)
296295
textField.text = nil
297296

@@ -336,12 +335,12 @@ public class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDele
336335

337336
// MARK: - UIResponder Callbacks
338337

339-
@objc private func togglePlaceholderIfNeeded(_ sender: UITextField? = nil) {
338+
@objc fileprivate func togglePlaceholderIfNeeded(_ sender: UITextField? = nil) {
340339
let showsPlaceholder = tokens.isEmpty && (inputTextField.text?.isEmpty ?? true)
341340
placeholderLabel.isHidden = !showsPlaceholder
342341
}
343342

344-
@objc private func handleTapGesture(_ sender: UITapGestureRecognizer) {
343+
@objc fileprivate func handleTapGesture(_ sender: UITapGestureRecognizer) {
345344
if !isFirstResponder {
346345
inputTextField.becomeFirstResponder()
347346
}

0 commit comments

Comments
 (0)