Skip to content

Commit ecaccde

Browse files
committed
Convert to Swift 3 syntax
1 parent c19d19e commit ecaccde

15 files changed

Lines changed: 175 additions & 175 deletions

Example/Example.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@
363363
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
364364
PRODUCT_BUNDLE_IDENTIFIER = com.polydice.ICInputAccessoryUITests;
365365
PRODUCT_NAME = "$(TARGET_NAME)";
366-
SWIFT_VERSION = 2.3;
366+
SWIFT_VERSION = 3.0;
367367
TEST_TARGET_NAME = Example;
368368
USES_XCTRUNNER = YES;
369369
};
@@ -376,7 +376,7 @@
376376
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
377377
PRODUCT_BUNDLE_IDENTIFIER = com.polydice.ICInputAccessoryUITests;
378378
PRODUCT_NAME = "$(TARGET_NAME)";
379-
SWIFT_VERSION = 2.3;
379+
SWIFT_VERSION = 3.0;
380380
TEST_TARGET_NAME = Example;
381381
USES_XCTRUNNER = YES;
382382
};
@@ -473,7 +473,7 @@
473473
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
474474
PRODUCT_BUNDLE_IDENTIFIER = com.polydice.ICInputAccessoryExample;
475475
PRODUCT_NAME = "$(TARGET_NAME)";
476-
SWIFT_VERSION = 2.3;
476+
SWIFT_VERSION = 3.0;
477477
TARGETED_DEVICE_FAMILY = "1,2";
478478
};
479479
name = Debug;
@@ -488,7 +488,7 @@
488488
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
489489
PRODUCT_BUNDLE_IDENTIFIER = com.polydice.ICInputAccessoryExample;
490490
PRODUCT_NAME = "$(TARGET_NAME)";
491-
SWIFT_VERSION = 2.3;
491+
SWIFT_VERSION = 3.0;
492492
TARGETED_DEVICE_FAMILY = "1,2";
493493
};
494494
name = Release;

Example/Example/AppDelegate.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3131

3232
var window: UIWindow?
3333

34-
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
35-
window = UIWindow(frame: UIScreen.mainScreen().bounds)
36-
window?.backgroundColor = UIColor.whiteColor()
34+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
35+
window = UIWindow(frame: UIScreen.main.bounds)
36+
window?.backgroundColor = UIColor.white
3737
window?.rootViewController = UINavigationController(rootViewController: ExampleViewController())
3838
window?.makeKeyAndVisible()
3939
return true

Example/Example/CustomizedTokenField.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,31 +52,31 @@ extension ICTokenField {
5252

5353
layer.cornerRadius = 5
5454
layer.shouldRasterize = true
55-
layer.rasterizationScale = UIScreen.mainScreen().scale
55+
layer.rasterizationScale = UIScreen.main().scale
5656
backgroundColor = UIColor(red:0.8, green:0.32, blue:0.24, alpha:1)
5757

58-
textField.textColor = UIColor.whiteColor()
59-
textField.tintColor = UIColor.whiteColor()
60-
textField.font = UIFont.boldSystemFontOfSize(14)
58+
textField.textColor = UIColor.white()
59+
textField.tintColor = UIColor.white()
60+
textField.font = UIFont.boldSystemFont(ofSize: 14)
6161

62-
attributedPlaceholder = NSAttributedString(
62+
attributedPlaceholder = AttributedString(
6363
string: String(self.dynamicType),
6464
attributes: [
65-
NSForegroundColorAttributeName: UIColor.whiteColor().colorWithAlphaComponent(0.5),
66-
NSFontAttributeName: UIFont.boldSystemFontOfSize(14)
65+
NSForegroundColorAttributeName: UIColor.white().withAlphaComponent(0.5),
66+
NSFontAttributeName: UIFont.boldSystemFont(ofSize: 14)
6767
]
6868
)
6969

7070
normalTokenAttributes = [
71-
NSForegroundColorAttributeName: UIColor.whiteColor(),
72-
NSBackgroundColorAttributeName: UIColor.whiteColor().colorWithAlphaComponent(0.25),
73-
NSFontAttributeName: UIFont.boldSystemFontOfSize(14)
71+
NSForegroundColorAttributeName: UIColor.white(),
72+
NSBackgroundColorAttributeName: UIColor.white().withAlphaComponent(0.25),
73+
NSFontAttributeName: UIFont.boldSystemFont(ofSize: 14)
7474
]
7575

7676
highlightedTokenAttributes = [
7777
NSForegroundColorAttributeName: UIColor(red:0.8, green:0.32, blue:0.24, alpha:1),
78-
NSBackgroundColorAttributeName: UIColor.whiteColor(),
79-
NSFontAttributeName: UIFont.boldSystemFontOfSize(14)
78+
NSBackgroundColorAttributeName: UIColor.white(),
79+
NSFontAttributeName: UIFont.boldSystemFont(ofSize: 14)
8080
]
8181
}
8282

Example/Example/CustomizedTokenViewController.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,73 +36,73 @@ class CustomizedTokenViewController: UIViewController, ICTokenFieldDelegate {
3636

3737
override func loadView() {
3838
super.loadView()
39-
view.backgroundColor = UIColor.whiteColor()
39+
view.backgroundColor = UIColor.white
4040
textView.text = "[\n\n]";
41-
textView.font = UIFont.preferredFontForTextStyle(UIFontTextStyleSubheadline)
41+
textView.font = UIFont.preferredFont(forTextStyle: UIFontTextStyleSubheadline)
4242
textView.frame = view.bounds.insetBy(dx: 10, dy: 10)
43-
textView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
43+
textView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
4444
view.addSubview(textView)
4545
}
4646

4747
override func viewDidLoad() {
4848
super.viewDidLoad()
4949
navigationController?.navigationBar.barTintColor = UIColor(red:0.96, green:0.48, blue:0.4, alpha:1)
50-
navigationController?.navigationBar.translucent = false
51-
navigationController?.navigationBar.barStyle = .Black
50+
navigationController?.navigationBar.isTranslucent = false
51+
navigationController?.navigationBar.barStyle = .black
5252

53-
let cancelBarButton = UIBarButtonItem(barButtonSystemItem: .Cancel, target: self, action: .dismiss)
54-
cancelBarButton.tintColor = UIColor.whiteColor()
53+
let cancelBarButton = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: .dismiss)
54+
cancelBarButton.tintColor = UIColor.white
5555
navigationItem.rightBarButtonItem = cancelBarButton
5656

5757
navigationItem.titleView = tokenField
5858
tokenField.delegate = self
5959
}
6060

61-
override func viewWillAppear(animated: Bool) {
61+
override func viewWillAppear(_ animated: Bool) {
6262
super.viewWillAppear(animated)
6363
tokenField.becomeFirstResponder()
6464
}
6565

66-
override func viewWillDisappear(animated: Bool) {
66+
override func viewWillDisappear(_ animated: Bool) {
6767
super.viewWillAppear(animated)
6868
tokenField.resignFirstResponder()
6969
textView.endEditing(true)
7070
}
7171

7272
// MARK: - ICTokenFieldDelegate
7373

74-
func tokenFieldDidBeginEditing(tokenField: ICTokenField) {
74+
func tokenFieldDidBeginEditing(_ tokenField: ICTokenField) {
7575
print(#function)
7676
}
7777

78-
func tokenFieldDidEndEditing(tokenField: ICTokenField) {
78+
func tokenFieldDidEndEditing(_ tokenField: ICTokenField) {
7979
print(#function)
8080
}
8181

82-
func tokenFieldWillReturn(tokenField: ICTokenField) {
82+
func tokenFieldWillReturn(_ tokenField: ICTokenField) {
8383
print(#function)
8484
}
8585

86-
func tokenField(tokenField: ICTokenField, didEnterText text: String) {
86+
func tokenField(_ tokenField: ICTokenField, didEnterText text: String) {
8787
print("Add: \"\(text)\"")
8888
updateTexts()
8989
}
9090

91-
func tokenField(tokenField: ICTokenField, didDeleteText text: String, atIndex index: Int) {
91+
func tokenField(_ tokenField: ICTokenField, didDeleteText text: String, atIndex index: Int) {
9292
print("Delete: \"\(text)\"")
9393
updateTexts()
9494
}
9595

9696
// MARK: - UIResponder Callbacks
9797

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

102102
// MARK: - Private Methods
103103

104104
private func updateTexts() {
105-
textView.text = "[\n " + tokenField.texts.map { "\"" + $0 + "\"" } .joinWithSeparator(",\n ") + "\n]"
105+
textView.text = "[\n " + tokenField.texts.map { "\"" + $0 + "\"" } .joined(separator: ",\n ") + "\n]"
106106
}
107107

108108
}

Example/Example/ExampleCell.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ class ExampleCell: UITableViewCell {
3636
displayingView.translatesAutoresizingMaskIntoConstraints = false
3737

3838
if #available(iOS 9.0, *) {
39-
displayingView.topAnchor.constraintEqualToAnchor(contentView.topAnchor).active = true
40-
displayingView.leftAnchor.constraintEqualToAnchor(contentView.leftAnchor).active = true
41-
displayingView.bottomAnchor.constraintEqualToAnchor(contentView.bottomAnchor).active = true
42-
displayingView.rightAnchor.constraintEqualToAnchor(contentView.rightAnchor).active = true
39+
displayingView.topAnchor.constraint(equalTo: contentView.topAnchor).isActive = true
40+
displayingView.leftAnchor.constraint(equalTo: contentView.leftAnchor).isActive = true
41+
displayingView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor).isActive = true
42+
displayingView.rightAnchor.constraint(equalTo: contentView.rightAnchor).isActive = true
4343
} else {
4444
let views = ["view": displayingView]
45-
contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[view]|", options: [], metrics: nil, views: views))
46-
contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[view]|", options: [], metrics: nil, views: views))
45+
contentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[view]|", options: [], metrics: nil, views: views))
46+
contentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[view]|", options: [], metrics: nil, views: views))
4747
}
4848
}
4949
}
@@ -56,7 +56,7 @@ class ExampleCell: UITableViewCell {
5656
showcase?.removeFromSuperview()
5757
showcase = nil
5858
textLabel?.text = nil
59-
accessoryType = .None
59+
accessoryType = .none
6060
}
6161

6262
}

Example/Example/ExampleViewController.swift

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,40 +36,40 @@ class ExampleViewController: UITableViewController {
3636
]
3737

3838
private lazy var flipButton: UIButton = {
39-
let _button = UIButton(type: .System)
40-
_button.frame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 88)
41-
_button.setTitle("Storyboard", forState: .Normal)
42-
_button.addTarget(self, action: .showStoryboard, forControlEvents: .TouchUpInside)
39+
let _button = UIButton(type: .system)
40+
_button.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 88)
41+
_button.setTitle("Storyboard", for: UIControlState())
42+
_button.addTarget(self, action: .showStoryboard, for: .touchUpInside)
4343
return _button
4444
}()
4545

4646
// MARK: - Initialization
4747

4848
convenience init() {
49-
self.init(style: .Grouped)
49+
self.init(style: .grouped)
5050
title = "ICInputAccessory"
5151
}
5252

5353
// MARK: - UIViewController
5454

5555
override func loadView() {
5656
super.loadView()
57-
tableView.registerClass(ExampleCell.self, forCellReuseIdentifier: NSStringFromClass(ExampleCell.self))
57+
tableView.register(ExampleCell.self, forCellReuseIdentifier: NSStringFromClass(ExampleCell.self))
5858
tableView.tableFooterView = flipButton
59-
tableView.tableFooterView?.userInteractionEnabled
59+
tableView.tableFooterView?.isUserInteractionEnabled
6060
}
6161

6262
// MARK: - UITableViewDataSource
6363

64-
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
64+
override func numberOfSections(in tableView: UITableView) -> Int {
6565
return types.count
6666
}
6767

68-
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
68+
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
6969
return 1
7070
}
7171

72-
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
72+
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
7373
switch types[section] {
7474
case is ICKeyboardDismissTextField.Type:
7575
return "Dismiss Keyboard"
@@ -82,26 +82,26 @@ class ExampleViewController: UITableViewController {
8282
}
8383
}
8484

85-
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
86-
let cell = tableView.dequeueReusableCellWithIdentifier(NSStringFromClass(ExampleCell.self), forIndexPath: indexPath)
87-
switch types[indexPath.section] {
85+
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] {
8888
case let type as ICKeyboardDismissTextField.Type:
89-
let textField = type.init()
90-
textField.leftViewMode = .Always
89+
let textField = type.`init`(boundsSize:requestHandler:)()
90+
textField.leftViewMode = .always
9191
textField.leftView = UIView(frame: CGRect(x: 0, y: 0, width: 15, height: 15))
9292
textField.placeholder = String(type)
9393
(cell as? ExampleCell)?.showcase = textField
9494

9595
case let type as CustomizedTokenField.Type:
9696
cell.textLabel?.text = String(type)
97-
cell.accessoryType = .DisclosureIndicator
97+
cell.accessoryType = .disclosureIndicator
9898

9999
case let type as ICTokenField.Type:
100100
let container = UIView(frame: cell.bounds)
101-
let tokenField = type.init()
101+
let tokenField = type.`init`(boundsSize:requestHandler:)()
102102
tokenField.placeholder = String(type)
103103
tokenField.frame = container.bounds.insetBy(dx: 5, dy: 0)
104-
tokenField.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
104+
tokenField.autoresizingMask = [.flexibleWidth, .flexibleHeight]
105105
container.addSubview(tokenField)
106106
(cell as? ExampleCell)?.showcase = container
107107

@@ -113,22 +113,22 @@ class ExampleViewController: UITableViewController {
113113

114114
// MARK: - UITableViewDelegate
115115

116-
override func tableView(tableView: UITableView, shouldHighlightRowAtIndexPath indexPath: NSIndexPath) -> Bool {
117-
return types[indexPath.section] == CustomizedTokenField.self
116+
override func tableView(_ tableView: UITableView, shouldHighlightRowAt indexPath: IndexPath) -> Bool {
117+
return types[(indexPath as NSIndexPath).section] == CustomizedTokenField.self
118118
}
119119

120-
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
121-
if types[indexPath.section] == CustomizedTokenField.self {
122-
presentViewController(UINavigationController(rootViewController: CustomizedTokenViewController()), animated: true, completion: nil)
120+
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
121+
if types[(indexPath as NSIndexPath).section] == CustomizedTokenField.self {
122+
present(UINavigationController(rootViewController: CustomizedTokenViewController()), animated: true, completion: nil)
123123
}
124124
}
125125

126126
// MARK: - UIResponder Callbacks
127127

128-
@objc private func showStoryboard(sender: UIButton) {
129-
if let controller = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()).instantiateInitialViewController() {
130-
controller.modalTransitionStyle = .FlipHorizontal
131-
presentViewController(controller, animated: true, completion: nil)
128+
@objc private func showStoryboard(_ sender: UIButton) {
129+
if let controller = UIStoryboard(name: "Main", bundle: Bundle.main).instantiateInitialViewController() {
130+
controller.modalTransitionStyle = .flipHorizontal
131+
present(controller, animated: true, completion: nil)
132132
}
133133
}
134134

Example/Example/StoryboardViewController.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ class StoryboardViewController: UITableViewController {
3232
@IBOutlet weak var tokenField: ICTokenField! {
3333
didSet {
3434
tokenField.normalTokenAttributes = [
35-
NSForegroundColorAttributeName: UIColor.whiteColor(),
36-
NSBackgroundColorAttributeName: UIColor.whiteColor().colorWithAlphaComponent(0.25),
35+
NSForegroundColorAttributeName: UIColor.white(),
36+
NSBackgroundColorAttributeName: UIColor.white().withAlphaComponent(0.25),
3737
]
3838

3939
tokenField.highlightedTokenAttributes = [
40-
NSForegroundColorAttributeName: UIColor.darkGrayColor(),
41-
NSBackgroundColorAttributeName: UIColor.whiteColor(),
40+
NSForegroundColorAttributeName: UIColor.darkGray(),
41+
NSBackgroundColorAttributeName: UIColor.white(),
4242
]
4343
}
4444
}
4545

46-
@IBAction func dismiss(sender: UIButton) {
47-
presentingViewController?.dismissViewControllerAnimated(true, completion: nil)
46+
@IBAction func dismiss(_ sender: UIButton) {
47+
presentingViewController?.dismiss(animated: true, completion: nil)
4848
}
4949

5050
}

Example/ICInputAccessoryUITests/ICKeyboardDismissTextFieldUITests.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ class ICKeyboardDismissTextFieldUITests: XCTestCase {
4545
let app = XCUIApplication()
4646
app.tables.cells.textFields["ICKeyboardDismissTextField"].tap()
4747

48-
let keyboardWindow = app.childrenMatchingType(.Window).elementBoundByIndex(1)
49-
let accessory = keyboardWindow.childrenMatchingType(.Other).element.childrenMatchingType(.Other).element.childrenMatchingType(.Other).elementBoundByIndex(0)
50-
accessory.childrenMatchingType(.Button).element.tap()
48+
let keyboardWindow = app.children(matching: .window).element(boundBy: 1)
49+
let accessory = keyboardWindow.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element(boundBy: 0)
50+
accessory.children(matching: .button).element.tap()
5151
}
5252

5353
func testStoryboard() {
@@ -57,11 +57,11 @@ class ICKeyboardDismissTextFieldUITests: XCTestCase {
5757
tablesQuery.buttons["Storyboard"].tap()
5858
tablesQuery.textFields["Storyboard ICKeyboardDismissTextField"].tap()
5959

60-
let keyboardWindow = app.childrenMatchingType(.Window).elementBoundByIndex(1)
61-
let accessory = keyboardWindow.childrenMatchingType(.Other).element.childrenMatchingType(.Other).element.childrenMatchingType(.Other).elementBoundByIndex(0)
62-
accessory.childrenMatchingType(.Button).element.tap()
60+
let keyboardWindow = app.children(matching: .window).element(boundBy: 1)
61+
let accessory = keyboardWindow.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element(boundBy: 0)
62+
accessory.children(matching: .button).element.tap()
6363

6464
tablesQuery.buttons["Back to Code"].tap()
6565
}
6666

67-
}
67+
}

0 commit comments

Comments
 (0)