Skip to content
This repository was archived by the owner on Mar 10, 2022. It is now read-only.

Commit 9eafcf9

Browse files
kasperwelnerDominik Hadl
authored andcommitted
Updated to Swift 3.0
1 parent a3a16a5 commit 9eafcf9

File tree

6 files changed

+60
-58
lines changed

6 files changed

+60
-58
lines changed

KeyboardHelper.xcodeproj/project.pbxproj

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
isa = PBXProject;
185185
attributes = {
186186
LastSwiftUpdateCheck = 0720;
187-
LastUpgradeCheck = 0720;
187+
LastUpgradeCheck = 0800;
188188
ORGANIZATIONNAME = Nodes;
189189
TargetAttributes = {
190190
275BCA761C57C9F800FF3647 = {
@@ -364,7 +364,7 @@
364364
SKIP_INSTALL = YES;
365365
SWIFT_OBJC_INTERFACE_HEADER_NAME = "$(SWIFT_MODULE_NAME)-Swift.h";
366366
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
367-
SWIFT_VERSION = 2.3;
367+
SWIFT_VERSION = 3.0;
368368
};
369369
name = Debug;
370370
};
@@ -382,7 +382,8 @@
382382
PRODUCT_NAME = "$(TARGET_NAME)";
383383
SKIP_INSTALL = YES;
384384
SWIFT_OBJC_INTERFACE_HEADER_NAME = "$(SWIFT_MODULE_NAME)-Swift.h";
385-
SWIFT_VERSION = 2.3;
385+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
386+
SWIFT_VERSION = 3.0;
386387
};
387388
name = Release;
388389
};
@@ -393,7 +394,7 @@
393394
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
394395
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.KeyboardHelperTests;
395396
PRODUCT_NAME = "$(TARGET_NAME)";
396-
SWIFT_VERSION = 2.3;
397+
SWIFT_VERSION = 3.0;
397398
};
398399
name = Debug;
399400
};
@@ -404,7 +405,8 @@
404405
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
405406
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.KeyboardHelperTests;
406407
PRODUCT_NAME = "$(TARGET_NAME)";
407-
SWIFT_VERSION = 2.3;
408+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
409+
SWIFT_VERSION = 3.0;
408410
};
409411
name = Release;
410412
};

KeyboardHelper.xcodeproj/xcshareddata/xcschemes/KeyboardHelper.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0720"
3+
LastUpgradeVersion = "0800"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

KeyboardHelper/Classes/KeyboardAppearanceInfo.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// KeyboardAppearanceInfo.swift
33
// KeyboardHelper
44
//
5-
// Created by Timmi Trinks on 04/02/16.
5+
// Created by Kasper Welner on 04/02/16.
66
// Copyright © 2016 Nodes. All rights reserved.
77
//
88

@@ -14,28 +14,28 @@ import UIKit
1414
*/
1515
public struct KeyboardAppearanceInfo {
1616

17-
public let notification: NSNotification
17+
public let notification: Notification
1818
public let userInfo: [NSObject: AnyObject]
1919

20-
public init(notification: NSNotification) {
20+
public init(notification: Notification) {
2121
self.notification = notification
22-
self.userInfo = notification.userInfo ?? [:]
22+
self.userInfo = (notification as NSNotification).userInfo ?? [:]
2323
}
2424

2525
/**
2626
Getter for the UIKeyboard frame begin infokey.
2727
Return a `CGRect` or `CGRectZero`.
2828
*/
2929
public var beginFrame: CGRect {
30-
return userInfo[UIKeyboardFrameBeginUserInfoKey]?.CGRectValue ?? CGRectZero
30+
return userInfo[UIKeyboardFrameBeginUserInfoKey]?.cgRectValue ?? CGRect.zero
3131
}
3232

3333
/**
3434
Getter for the UIKeyboard frame end infokey.
3535
Return a `CGRect` or `CGRectZero`.
3636
*/
3737
public var endFrame: CGRect {
38-
return userInfo[UIKeyboardFrameEndUserInfoKey]?.CGRectValue ?? CGRectZero
38+
return userInfo[UIKeyboardFrameEndUserInfoKey]?.cgRectValue ?? CGRect.zero
3939
}
4040

4141
/**
@@ -64,8 +64,8 @@ public struct KeyboardAppearanceInfo {
6464
By default: `EaseInOut`.
6565
*/
6666
public var animationCurve: UIViewAnimationCurve {
67-
guard let value = userInfo[UIKeyboardAnimationCurveUserInfoKey] as? Int else { return .EaseInOut }
68-
return UIViewAnimationCurve(rawValue: value) ?? .EaseInOut
67+
guard let value = userInfo[UIKeyboardAnimationCurveUserInfoKey] as? Int else { return .easeInOut }
68+
return UIViewAnimationCurve(rawValue: value) ?? .easeInOut
6969
}
7070

7171
/**
@@ -84,12 +84,12 @@ public struct KeyboardAppearanceInfo {
8484
- animationBlock: Animation that should happen.
8585
- completion: Function that happens after the animation is finished.
8686
*/
87-
public func animateAlong(animationBlock: () -> Void, completion: (finished: Bool) -> Void) {
88-
UIView.animateWithDuration(
89-
animationDuration,
87+
public func animateAlong(_ animationBlock: () -> Void, completion: (finished: Bool) -> Void) {
88+
UIView.animate(
89+
withDuration: animationDuration,
9090
delay: 0.0,
9191
options: animationOptions,
9292
animations: animationBlock,
9393
completion: completion
9494
)}
95-
}
95+
}

KeyboardHelper/Classes/KeyboardHelper.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// KeyboardHelper.swift
33
// KeyboardHelper
44
//
5-
// Created by Timmi Trinks on 27/01/16.
5+
// Created by Kasper Welner on 27/01/16.
66
// Copyright © 2016 Nodes. All rights reserved.
77
//
88

@@ -19,13 +19,13 @@ public protocol KeyboardNotificationDelegate: class {
1919
This function will recongnize a change of `KeyboardAppearanceInfo` and will be fired when the keyboard will appaear.
2020
- Parameter info: Struct `KeyboardAppearanceInfo`.
2121
*/
22-
func keyboardWillAppear(info: KeyboardAppearanceInfo)
22+
func keyboardWillAppear(_ info: KeyboardAppearanceInfo)
2323

2424
/**
2525
This function will recongnize a change of `KeyboardAppearanceInfo` and will be fired when the keyboard will disappaear.
2626
- Parameter info: Struct `KeyboardAppearanceInfo`.
2727
*/
28-
func keyboardWillDisappear(info: KeyboardAppearanceInfo)
28+
func keyboardWillDisappear(_ info: KeyboardAppearanceInfo)
2929
}
3030

3131
/**
@@ -45,25 +45,25 @@ public class KeyboardHelper {
4545
required public init(delegate: KeyboardNotificationDelegate) {
4646
self.delegate = delegate
4747

48-
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(KeyboardHelper.keyboardWillAppear(_:)), name: UIKeyboardWillShowNotification, object: nil)
49-
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(KeyboardHelper.keyboardWillDisappear(_:)), name: UIKeyboardWillHideNotification, object: nil)
48+
NotificationCenter.default.addObserver(self, selector: #selector(KeyboardHelper.keyboardWillAppear(_:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
49+
NotificationCenter.default.addObserver(self, selector: #selector(KeyboardHelper.keyboardWillDisappear(_:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
5050
}
5151

5252
private init() {
5353
delegate = nil
5454
}
5555

56-
dynamic private func keyboardWillAppear(note: NSNotification) {
56+
dynamic private func keyboardWillAppear(_ note: Notification) {
5757
let info = KeyboardAppearanceInfo(notification: note)
5858
self.delegate?.keyboardWillAppear(info)
5959
}
6060

61-
dynamic private func keyboardWillDisappear(note: NSNotification) {
61+
dynamic private func keyboardWillDisappear(_ note: Notification) {
6262
let info = KeyboardAppearanceInfo(notification: note)
6363
self.delegate?.keyboardWillDisappear(info)
6464
}
6565

6666
deinit {
67-
NSNotificationCenter.defaultCenter().removeObserver(self)
67+
NotificationCenter.default.removeObserver(self)
6868
}
6969
}

KeyboardHelperTests/Tests/KeyboardAppearanceInfoTests.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ class KeyboardAppearanceInfoTests: XCTestCase {
1818
super.setUp()
1919

2020
// Create test info
21-
var testUserInfo: [String: AnyObject] = [
22-
UIKeyboardFrameBeginUserInfoKey: NSValue(CGRect: CGRect(x: 100, y: 100, width: 100, height: 100)),
23-
UIKeyboardFrameEndUserInfoKey: NSValue(CGRect: CGRect(x: 200, y: 200, width: 200, height: 200)),
21+
var testUserInfo: [String: Any] = [
22+
UIKeyboardFrameBeginUserInfoKey: NSValue(cgRect: CGRect(x: 100, y: 100, width: 100, height: 100)),
23+
UIKeyboardFrameEndUserInfoKey: NSValue(cgRect: CGRect(x: 200, y: 200, width: 200, height: 200)),
2424
UIKeyboardAnimationDurationUserInfoKey: 3.0,
25-
UIKeyboardAnimationCurveUserInfoKey: UIViewAnimationCurve.EaseOut.rawValue,
25+
UIKeyboardAnimationCurveUserInfoKey: NSNumber(integerLiteral: UIViewAnimationCurve.easeOut.rawValue),
2626
]
2727

2828
if #available(iOS 9.0, *) {
@@ -32,23 +32,23 @@ class KeyboardAppearanceInfoTests: XCTestCase {
3232
}
3333

3434
// Fake the notification
35-
let note = NSNotification(name: UIKeyboardWillShowNotification, object: nil, userInfo: testUserInfo)
35+
let note = Notification(name: NSNotification.Name.UIKeyboardWillShow, object: nil, userInfo: testUserInfo)
3636
apperanceInfo = KeyboardAppearanceInfo(notification: note)
37-
let defaultNote = NSNotification(name: UIKeyboardWillShowNotification, object: nil, userInfo: nil)
37+
let defaultNote = Notification(name: NSNotification.Name.UIKeyboardWillShow, object: nil, userInfo: nil)
3838
defaultsAppearanceInfo = KeyboardAppearanceInfo(notification: defaultNote)
3939
}
4040

4141
func testBeginFrame() {
4242
XCTAssertEqual(apperanceInfo.beginFrame, CGRect(x: 100, y: 100, width: 100, height: 100),
4343
"Parsing beginFrame from keyboard appearance info failed.")
44-
XCTAssertEqual(defaultsAppearanceInfo.beginFrame, CGRectZero,
44+
XCTAssertEqual(defaultsAppearanceInfo.beginFrame, CGRect.zero,
4545
"Parsing default beginFrame from keyboard appearance info failed.")
4646
}
4747

4848
func testEndFrame() {
4949
XCTAssertEqual(apperanceInfo.endFrame, CGRect(x: 200, y: 200, width: 200, height: 200),
5050
"Parsing endFrame from keyboard appearance info failed.")
51-
XCTAssertEqual(defaultsAppearanceInfo.endFrame, CGRectZero,
51+
XCTAssertEqual(defaultsAppearanceInfo.endFrame, CGRect.zero,
5252
"Parsing default endFrame from keyboard appearance info failed.")
5353
}
5454

@@ -75,7 +75,7 @@ class KeyboardAppearanceInfoTests: XCTestCase {
7575
}
7676

7777
func testAnimateAlong() {
78-
let expectation = expectationWithDescription("Animate along should take 3 seconds")
78+
let expectation = self.expectation(withDescription: "Animate along should take 3 seconds")
7979

8080
apperanceInfo.animateAlong({ () -> Void in
8181
// Do animations
@@ -85,7 +85,7 @@ class KeyboardAppearanceInfoTests: XCTestCase {
8585
}
8686
}
8787

88-
waitForExpectationsWithTimeout(3.005, handler: nil)
88+
waitForExpectations(withTimeout: 3.005, handler: nil)
8989
}
9090

9191
}

KeyboardHelperTests/Tests/KeyboardHelperTests.swift

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ class ShowSpyDelegate : KeyboardNotificationDelegate {
1414

1515
var expectation : XCTestExpectation?
1616

17-
func keyboardWillDisappear(info: KeyboardAppearanceInfo) {
17+
func keyboardWillDisappear(_ info: KeyboardAppearanceInfo) {
1818

1919
}
2020

21-
func keyboardWillAppear(info: KeyboardAppearanceInfo) {
21+
func keyboardWillAppear(_ info: KeyboardAppearanceInfo) {
2222
guard let expectation = expectation else {
2323
XCTFail("ShowSpyDelegate was not setup correctly. Missing XCTExpectation reference")
2424
return
@@ -34,7 +34,7 @@ class HideSpyDelegate : KeyboardNotificationDelegate {
3434

3535
var expectation : XCTestExpectation?
3636

37-
func keyboardWillDisappear(info: KeyboardAppearanceInfo) {
37+
func keyboardWillDisappear(_ info: KeyboardAppearanceInfo) {
3838
guard let expectation = expectation else {
3939
XCTFail("HideSpyDelegate was not setup correctly. Missing XCTExpectation reference")
4040
return
@@ -44,7 +44,7 @@ class HideSpyDelegate : KeyboardNotificationDelegate {
4444
expectation.fulfill()
4545
}
4646

47-
func keyboardWillAppear(info: KeyboardAppearanceInfo) {
47+
func keyboardWillAppear(_ info: KeyboardAppearanceInfo) {
4848

4949
}
5050
}
@@ -55,33 +55,33 @@ class KeyboardHelperTests: XCTestCase {
5555
let spyDelegate = ShowSpyDelegate()
5656
let kh = KeyboardHelper(delegate: spyDelegate)
5757

58-
let expectation = expectationWithDescription("KeyboardHelper calls the delegate as the result of receiving the show notification")
58+
let expectation = self.expectation(withDescription: "KeyboardHelper calls the delegate as the result of receiving the show notification")
5959
spyDelegate.expectation = expectation
6060

6161
// NSNotificationCenter.defaultCenter().postNotificationName(UIKeyboardWillShowNotification, object: kh)
62-
let notification : NSNotification
62+
let notification : Notification
6363
if #available(iOS 9.0, *) {
64-
notification = NSNotification(name: UIKeyboardWillShowNotification, object: kh, userInfo:[
65-
UIKeyboardAnimationCurveUserInfoKey : NSNumber(int: 7),
66-
UIKeyboardAnimationDurationUserInfoKey : NSNumber(double: 0.25),
67-
UIKeyboardFrameBeginUserInfoKey : NSValue(CGRect: CGRect(x: 0, y: 667, width: 375, height: 0)),
68-
UIKeyboardFrameEndUserInfoKey : NSValue(CGRect: CGRect(x: 0, y: 409, width: 375, height: 258)),
69-
UIKeyboardIsLocalUserInfoKey : NSNumber(bool: true)
64+
notification = Notification(name: NSNotification.Name.UIKeyboardWillShow, object: kh, userInfo:[
65+
UIKeyboardAnimationCurveUserInfoKey : NSNumber(value: 7),
66+
UIKeyboardAnimationDurationUserInfoKey : NSNumber(value: 0.25),
67+
UIKeyboardFrameBeginUserInfoKey : NSValue(cgRect: CGRect(x: 0, y: 667, width: 375, height: 0)),
68+
UIKeyboardFrameEndUserInfoKey : NSValue(cgRect: CGRect(x: 0, y: 409, width: 375, height: 258)),
69+
UIKeyboardIsLocalUserInfoKey : NSNumber(value: true)
7070
])
7171
} else {
72-
notification = NSNotification(name: UIKeyboardWillShowNotification, object: nil, userInfo:[
73-
UIKeyboardAnimationCurveUserInfoKey : NSNumber(int: 7),
74-
UIKeyboardAnimationDurationUserInfoKey : NSNumber(double: 0.25),
75-
UIKeyboardFrameBeginUserInfoKey : NSValue(CGRect: CGRect(x: 0, y: 667, width: 375, height: 0)),
76-
UIKeyboardFrameEndUserInfoKey : NSValue(CGRect: CGRect(x: 0, y: 409, width: 375, height: 258))
72+
notification = Notification(name: NSNotification.Name.UIKeyboardWillShow, object: nil, userInfo:[
73+
UIKeyboardAnimationCurveUserInfoKey : NSNumber(value: 7),
74+
UIKeyboardAnimationDurationUserInfoKey : NSNumber(value: 0.25),
75+
UIKeyboardFrameBeginUserInfoKey : NSValue(cgRect: CGRect(x: 0, y: 667, width: 375, height: 0)),
76+
UIKeyboardFrameEndUserInfoKey : NSValue(cgRect: CGRect(x: 0, y: 409, width: 375, height: 258))
7777
])
7878
}
7979

80-
NSNotificationCenter.defaultCenter().postNotification(notification)
80+
NotificationCenter.default.post(notification)
8181

8282

8383

84-
waitForExpectationsWithTimeout(1) { error in
84+
waitForExpectations(withTimeout: 1) { error in
8585
if let error = error {
8686
XCTFail("waitForExpectationsWithTimeout errored: \(error)")
8787
}
@@ -104,13 +104,13 @@ class KeyboardHelperTests: XCTestCase {
104104
let spyDelegate = HideSpyDelegate()
105105
let kh = KeyboardHelper(delegate: spyDelegate)
106106

107-
let expectation = expectationWithDescription("KeyboardHelper calls the delegate as the result of receiving the hide notification")
107+
let expectation = self.expectation(withDescription: "KeyboardHelper calls the delegate as the result of receiving the hide notification")
108108
spyDelegate.expectation = expectation
109109

110-
NSNotificationCenter.defaultCenter().postNotificationName(UIKeyboardWillHideNotification, object: kh)
110+
NotificationCenter.default.post(name: NSNotification.Name.UIKeyboardWillHide, object: kh)
111111

112112

113-
waitForExpectationsWithTimeout(1) { error in
113+
waitForExpectations(withTimeout: 1) { error in
114114
if let error = error {
115115
XCTFail("waitForExpectationsWithTimeout errored: \(error)")
116116
}

0 commit comments

Comments
 (0)