Skip to content
This repository was archived by the owner on Mar 10, 2022. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d6a6fb6

Browse files
authoredDec 14, 2016
Merge pull request #16 from nodes-ios/swift-3.0
Swift 3.0 version
2 parents a3a16a5 + 29108a0 commit d6a6fb6

File tree

13 files changed

+129
-123
lines changed

13 files changed

+129
-123
lines changed
 

‎Example/Cartfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
github "nodes-ios/KeyboardHelper" "master"
1+
github "nodes-ios/KeyboardHelper" "swift-3.0"

‎Example/Cartfile.resolved

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
github "nodes-ios/KeyboardHelper" "30ed3728bf10b7d2a606d1e23bb23c12eea02222"
1+
github "nodes-ios/KeyboardHelper" "58d7c2bf19f7bc93d733290f06ae0eedf03f18a5"

‎Example/KeyboardHelperDemo.xcodeproj/project.pbxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
TargetAttributes = {
129129
29F30E661C807E2A00C77AF4 = {
130130
CreatedOnToolsVersion = 7.2;
131+
LastSwiftMigration = 0810;
131132
};
132133
};
133134
};
@@ -289,6 +290,7 @@
289290
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
290291
PRODUCT_BUNDLE_IDENTIFIER = dk.nodes.KeyboardHelperDemo;
291292
PRODUCT_NAME = "$(TARGET_NAME)";
293+
SWIFT_VERSION = 3.0;
292294
};
293295
name = Debug;
294296
};
@@ -305,6 +307,7 @@
305307
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
306308
PRODUCT_BUNDLE_IDENTIFIER = dk.nodes.KeyboardHelperDemo;
307309
PRODUCT_NAME = "$(TARGET_NAME)";
310+
SWIFT_VERSION = 3.0;
308311
};
309312
name = Release;
310313
};

‎Example/KeyboardHelperDemo/AppDelegate.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1414
var window: UIWindow?
1515

1616

17-
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
17+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
1818
// Override point for customization after application launch.
1919
return true
2020
}
2121

22-
func applicationWillResignActive(application: UIApplication) {
22+
func applicationWillResignActive(_ application: UIApplication) {
2323
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
2424
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
2525
}
2626

27-
func applicationDidEnterBackground(application: UIApplication) {
27+
func applicationDidEnterBackground(_ application: UIApplication) {
2828
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
2929
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
3030
}
3131

32-
func applicationWillEnterForeground(application: UIApplication) {
32+
func applicationWillEnterForeground(_ application: UIApplication) {
3333
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
3434
}
3535

36-
func applicationDidBecomeActive(application: UIApplication) {
36+
func applicationDidBecomeActive(_ application: UIApplication) {
3737
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
3838
}
3939

40-
func applicationWillTerminate(application: UIApplication) {
40+
func applicationWillTerminate(_ application: UIApplication) {
4141
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
4242
}
4343

‎Example/KeyboardHelperDemo/ViewController.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import KeyboardHelper
1111

1212
class ViewController: UIViewController, KeyboardNotificationDelegate {
1313

14-
private var tapGesture: UITapGestureRecognizer!
15-
private var keyboardHelper : KeyboardHelper?
14+
fileprivate var tapGesture: UITapGestureRecognizer!
15+
fileprivate var keyboardHelper : KeyboardHelper?
1616
@IBOutlet weak var scrollView: UIScrollView!
1717

1818
override func viewDidLoad() {
@@ -21,7 +21,7 @@ class ViewController: UIViewController, KeyboardNotificationDelegate {
2121

2222
self.tapGesture = UITapGestureRecognizer(target: self, action: #selector(ViewController.dismissKeyboard))
2323
self.view.addGestureRecognizer(tapGesture)
24-
self.tapGesture.enabled = true
24+
self.tapGesture.isEnabled = true
2525

2626
self.keyboardHelper = KeyboardHelper(delegate: self)
2727
}
@@ -30,20 +30,20 @@ class ViewController: UIViewController, KeyboardNotificationDelegate {
3030
self.view.endEditing(true)
3131
}
3232

33-
func keyboardWillAppear(info: KeyboardAppearanceInfo) {
33+
func keyboardWillAppear(_ info: KeyboardAppearanceInfo) {
3434
info.animateAlong({ () -> Void in
3535
let insets = UIEdgeInsetsMake(0, 0, info.endFrame.size.height, 0)
3636
self.scrollView.contentInset = insets
3737
self.scrollView.scrollIndicatorInsets = insets
3838
}) { finished in }
3939
}
4040

41-
func keyboardWillDisappear(info: KeyboardAppearanceInfo) {
42-
UIView.animateWithDuration(NSTimeInterval(info.animationDuration),
41+
func keyboardWillDisappear(_ info: KeyboardAppearanceInfo) {
42+
UIView.animate(withDuration: TimeInterval(info.animationDuration),
4343
delay: 0,
4444
options: info.animationOptions,
4545
animations: {
46-
let insets = UIEdgeInsetsZero
46+
let insets = UIEdgeInsets.zero
4747
self.scrollView.contentInset = insets
4848
self.scrollView.scrollIndicatorInsets = insets
4949
},

‎KeyboardHelper.podspec

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
1616
#
1717

1818
s.name = "KeyboardHelper"
19-
s.version = "0.9.2"
19+
s.version = "1.0.0"
2020
s.summary = "Handle UIKeyboard with ease, delegation and strongly typed user info included!"
2121

2222
# This description is used to generate tags and improve search results.
@@ -66,7 +66,7 @@ Pod::Spec.new do |s|
6666
# s.platform = :ios, "5.0"
6767

6868
# When using multiple platforms
69-
s.ios.deployment_target = "8.1"
69+
s.ios.deployment_target = "8.0"
7070
# s.osx.deployment_target = "10.7"
7171
# s.watchos.deployment_target = "2.0"
7272
# s.tvos.deployment_target = "9.0"
@@ -78,7 +78,7 @@ Pod::Spec.new do |s|
7878
# Supports git, hg, bzr, svn and HTTP.
7979
#
8080

81-
s.source = { :git => "https://github.com/nodes-ios/KeyboardHelper.git", :tag => "0.9.2" }
81+
s.source = { :git => "https://github.com/nodes-ios/KeyboardHelper.git", :tag => s.version }
8282

8383

8484
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
@@ -134,4 +134,3 @@ Pod::Spec.new do |s|
134134
# s.dependency "JSONKit", "~> 1.4"
135135

136136
end
137-

‎KeyboardHelper.xcodeproj/project.pbxproj

Lines changed: 11 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 = 0810;
188188
ORGANIZATIONNAME = Nodes;
189189
TargetAttributes = {
190190
275BCA761C57C9F800FF3647 = {
@@ -275,8 +275,10 @@
275275
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
276276
CLANG_WARN_EMPTY_BODY = YES;
277277
CLANG_WARN_ENUM_CONVERSION = YES;
278+
CLANG_WARN_INFINITE_RECURSION = YES;
278279
CLANG_WARN_INT_CONVERSION = YES;
279280
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
281+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
280282
CLANG_WARN_UNREACHABLE_CODE = YES;
281283
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
282284
COPY_PHASE_STRIP = NO;
@@ -322,8 +324,10 @@
322324
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
323325
CLANG_WARN_EMPTY_BODY = YES;
324326
CLANG_WARN_ENUM_CONVERSION = YES;
327+
CLANG_WARN_INFINITE_RECURSION = YES;
325328
CLANG_WARN_INT_CONVERSION = YES;
326329
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
330+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
327331
CLANG_WARN_UNREACHABLE_CODE = YES;
328332
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
329333
COPY_PHASE_STRIP = NO;
@@ -364,7 +368,7 @@
364368
SKIP_INSTALL = YES;
365369
SWIFT_OBJC_INTERFACE_HEADER_NAME = "$(SWIFT_MODULE_NAME)-Swift.h";
366370
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
367-
SWIFT_VERSION = 2.3;
371+
SWIFT_VERSION = 3.0;
368372
};
369373
name = Debug;
370374
};
@@ -382,7 +386,8 @@
382386
PRODUCT_NAME = "$(TARGET_NAME)";
383387
SKIP_INSTALL = YES;
384388
SWIFT_OBJC_INTERFACE_HEADER_NAME = "$(SWIFT_MODULE_NAME)-Swift.h";
385-
SWIFT_VERSION = 2.3;
389+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
390+
SWIFT_VERSION = 3.0;
386391
};
387392
name = Release;
388393
};
@@ -393,7 +398,7 @@
393398
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
394399
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.KeyboardHelperTests;
395400
PRODUCT_NAME = "$(TARGET_NAME)";
396-
SWIFT_VERSION = 2.3;
401+
SWIFT_VERSION = 3.0;
397402
};
398403
name = Debug;
399404
};
@@ -404,7 +409,8 @@
404409
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
405410
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.KeyboardHelperTests;
406411
PRODUCT_NAME = "$(TARGET_NAME)";
407-
SWIFT_VERSION = 2.3;
412+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
413+
SWIFT_VERSION = 3.0;
408414
};
409415
name = Release;
410416
};

‎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 = "0810"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

‎KeyboardHelper/Classes/KeyboardAppearanceInfo.swift

Lines changed: 14 additions & 14 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,10 +14,10 @@ import UIKit
1414
*/
1515
public struct KeyboardAppearanceInfo {
1616

17-
public let notification: NSNotification
18-
public let userInfo: [NSObject: AnyObject]
17+
public let notification: Notification
18+
public let userInfo: [AnyHashable: Any]
1919

20-
public init(notification: NSNotification) {
20+
public init(notification: Notification) {
2121
self.notification = notification
2222
self.userInfo = notification.userInfo ?? [:]
2323
}
@@ -27,15 +27,15 @@ public struct KeyboardAppearanceInfo {
2727
Return a `CGRect` or `CGRectZero`.
2828
*/
2929
public var beginFrame: CGRect {
30-
return userInfo[UIKeyboardFrameBeginUserInfoKey]?.CGRectValue ?? CGRectZero
30+
return (userInfo[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue ?? .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] as? NSValue)?.cgRectValue ?? .zero
3939
}
4040

4141
/**
@@ -45,7 +45,7 @@ public struct KeyboardAppearanceInfo {
4545
*/
4646
public var belongsToCurrentApp: Bool {
4747
if #available(iOS 9.0, *) {
48-
return userInfo[UIKeyboardIsLocalUserInfoKey]?.boolValue ?? true
48+
return (userInfo[UIKeyboardIsLocalUserInfoKey] as? Bool) ?? true
4949
} else {
5050
return true
5151
}
@@ -56,16 +56,16 @@ public struct KeyboardAppearanceInfo {
5656
By default: `0.25`.
5757
*/
5858
public var animationDuration: Double {
59-
return userInfo[UIKeyboardAnimationDurationUserInfoKey]?.doubleValue ?? 0.25
59+
return (userInfo[UIKeyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue ?? 0.25
6060
}
6161

6262
/**
6363
Getter for the animation curve.
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: @escaping (() -> Void), completion: @escaping ((_ finished: Bool) -> Void) = { _ in }) {
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: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ import KeyboardHelper
1111

1212
class KeyboardAppearanceInfoTests: XCTestCase {
1313

14-
var apperanceInfo: KeyboardAppearanceInfo!
14+
var appearanceInfo: KeyboardAppearanceInfo!
1515
var defaultsAppearanceInfo : KeyboardAppearanceInfo!
1616

1717
override func setUp() {
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,60 +32,61 @@ class KeyboardAppearanceInfoTests: XCTestCase {
3232
}
3333

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

4141
func testBeginFrame() {
42-
XCTAssertEqual(apperanceInfo.beginFrame, CGRect(x: 100, y: 100, width: 100, height: 100),
42+
XCTAssertEqual(appearanceInfo.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() {
49-
XCTAssertEqual(apperanceInfo.endFrame, CGRect(x: 200, y: 200, width: 200, height: 200),
49+
XCTAssertEqual(appearanceInfo.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

5555
@available(iOS 9.0, *)
5656
func testBelongsToCurrentApp() {
57-
XCTAssertEqual(apperanceInfo.belongsToCurrentApp, false,
57+
XCTAssertEqual(appearanceInfo.belongsToCurrentApp, false,
5858
"Parsing belongsToCurrentApp from keyboard appearance info failed.")
5959
XCTAssertEqual(defaultsAppearanceInfo.belongsToCurrentApp, true,
6060
"Parsing default belongsToCurrentApp from keyboard appearance info failed.")
6161
}
6262

6363
func testAnimationDuration() {
64-
XCTAssertEqual(apperanceInfo.animationDuration, Double(3),
64+
65+
XCTAssertEqual(appearanceInfo.animationDuration, Double(3),
6566
"Parsing animationDuration from keyboard appearance info failed.")
6667
XCTAssertEqual(defaultsAppearanceInfo.animationDuration, Double(0.25),
6768
"Parsing default animationDuration from keyboard appearance info failed.")
6869
}
6970

7071
func testAnimationCurve() {
71-
XCTAssertEqual(apperanceInfo.animationCurve, UIViewAnimationCurve(rawValue: 2),
72+
XCTAssertEqual(appearanceInfo.animationCurve, UIViewAnimationCurve(rawValue: 2),
7273
"Parsing animationCurve from keyboard appearance info failed.")
7374
XCTAssertEqual(defaultsAppearanceInfo.animationCurve, UIViewAnimationCurve(rawValue: defaultsAppearanceInfo.animationCurve.rawValue),
7475
"Parsing default animationCurve from keyboard appearance info failed.")
7576
}
7677

7778
func testAnimateAlong() {
78-
let expectation = expectationWithDescription("Animate along should take 3 seconds")
79+
let expectation = self.expectation(description: "Animate along should take 3 seconds")
7980

80-
apperanceInfo.animateAlong({ () -> Void in
81+
appearanceInfo.animateAlong({ () -> Void in
8182
// Do animations
8283
}) { (finished) -> Void in
8384
if finished {
8485
expectation.fulfill()
8586
}
8687
}
8788

88-
waitForExpectationsWithTimeout(3.005, handler: nil)
89+
waitForExpectations(timeout: 3.005, handler: nil)
8990
}
9091

9192
}

‎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(description: "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(timeout: 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(description: "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(timeout: 1) { error in
114114
if let error = error {
115115
XCTFail("waitForExpectationsWithTimeout errored: \(error)")
116116
}

‎README.md

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,23 @@ A small (but cool) tool for handling UIKeyboard appearing and disappearing in yo
1515
## 📦 Installation
1616

1717
### Carthage
18+
~~~bash
19+
github "nodes-ios/KeyboardHelper" ~> 1.0
1820
~~~
19-
github "nodes-ios/KeyboardHelper"
20-
~~~
21+
22+
> Last versions compatible with lower Swift versions:
23+
>
24+
> **Swift 2.3**
25+
> `github "nodes-ios/KeyboardHelper" == 0.10.0`
26+
>
27+
> **Swift 2.2**
28+
> `github "nodes-ios/KeyboardHelper" == 0.9.4`
2129
2230
### CocoaPods
2331
~~~
24-
pod 'KeyboardHelper', '~> 0.9'
32+
pod 'KeyboardHelper', '~> 1.0'
2533
~~~
2634

27-
### Swit Package Manager
28-
To use KeyboardHelper as a [Swift Package Manager](https://swift.org/package-manager/) package just add the following to your `Package.swift` file.
29-
30-
~~~swift
31-
import PackageDescription
32-
33-
let package = Package(
34-
name: "YourPackage",
35-
dependencies: [
36-
.Package(url: "https://github.com/nodes-ios/KeyboardHelper.git", majorVersion: 0)
37-
]
38-
)
39-
~~~
40-
41-
**NOTE:** This doesn't currently work as SPM doesn't support iOS, but once it will we will already be supporting it! :)
4235

4336
## 🔧 Setup
4437
Implement `KeyboardNotificationDelegate` in your UIViewController.
@@ -47,27 +40,31 @@ Implement `KeyboardNotificationDelegate` in your UIViewController.
4740
class ViewController: UIViewController, KeyboardNotificationDelegate
4841
```
4942

50-
Add a `KeyboardHelper` private variable and initialize it, setting the delegate.
43+
Add a `KeyboardHelper` private variable, initialize it and set the delegate.
5144

5245
```swift
5346
private var keyboardHelper : KeyboardHelper?
54-
...
55-
self.keyboardHelper = KeyboardHelper(delegate: self)
47+
48+
func viewDidLoad() {
49+
...
50+
self.keyboardHelper = KeyboardHelper(delegate: self)
51+
...
52+
}
5653
```
5754
Implement the two methods in the `KeyboardNotificationDelegate`:
5855

5956
```swift
60-
public func keyboardWillAppear(info: KeyboardHelper.KeyboardAppearanceInfo)
61-
public func keyboardWillDisappear(info: KeyboardHelper.KeyboardAppearanceInfo)
57+
public func keyboardWillAppear(_ info: KeyboardHelper.KeyboardAppearanceInfo)
58+
public func keyboardWillDisappear(_ info: KeyboardHelper.KeyboardAppearanceInfo)
6259
```
6360

6461
Both methods take as argument a `KeyboardAppearanceInfo` object, which is basically a wrapper over the `userInfo` dictionary of the `UIKeyboardWillShowNotification` and `UIKeyboardWillHideNotification` notifications.
6562

6663
One example of implementation for the two delegate methods is:
6764

6865
```swift
69-
func keyboardWillAppear(info: KeyboardAppearanceInfo) {
70-
UIView.animateWithDuration(NSTimeInterval(info.animationDuration),
66+
func keyboardWillAppear(_ info: KeyboardAppearanceInfo) {
67+
UIView.animate(withDuration: TimeInterval(info.animationDuration),
7168
delay: 0,
7269
options: info.animationOptions,
7370
animations: {
@@ -78,17 +75,17 @@ func keyboardWillAppear(info: KeyboardAppearanceInfo) {
7875
completion:nil)
7976
}
8077

81-
func keyboardWillDisappear(info: KeyboardAppearanceInfo) {
82-
UIView.animateWithDuration(NSTimeInterval(info.animationDuration),
83-
delay: 0,
84-
options: info.animationOptions,
85-
animations: {
86-
let insets = UIEdgeInsetsZero
87-
self.scrollView.contentInset = insets
88-
self.scrollView.scrollIndicatorInsets = insets
89-
},
90-
completion:nil)
91-
}
78+
func keyboardWillDisappear(_ info: KeyboardAppearanceInfo) {
79+
UIView.animate(withDuration: TimeInterval(info.animationDuration),
80+
delay: 0,
81+
options: info.animationOptions,
82+
animations: {
83+
let insets = UIEdgeInsetsZero
84+
self.scrollView.contentInset = insets
85+
self.scrollView.scrollIndicatorInsets = insets
86+
},
87+
completion:nil)
88+
}
9289
```
9390

9491
The `KeyboardAppearanceInfo` object has the following properties:

0 commit comments

Comments
 (0)
This repository has been archived.