From 9eafcf9d7e8ebf071ddd35b1c415e5b250686fee Mon Sep 17 00:00:00 2001 From: Kasper Welner Date: Mon, 11 Jul 2016 13:13:11 +0200 Subject: [PATCH 1/8] Updated to Swift 3.0 --- KeyboardHelper.xcodeproj/project.pbxproj | 12 ++--- .../xcschemes/KeyboardHelper.xcscheme | 2 +- .../Classes/KeyboardAppearanceInfo.swift | 24 +++++----- KeyboardHelper/Classes/KeyboardHelper.swift | 16 +++---- .../Tests/KeyboardAppearanceInfoTests.swift | 20 ++++----- .../Tests/KeyboardHelperTests.swift | 44 +++++++++---------- 6 files changed, 60 insertions(+), 58 deletions(-) diff --git a/KeyboardHelper.xcodeproj/project.pbxproj b/KeyboardHelper.xcodeproj/project.pbxproj index 9dcabb6..2499261 100644 --- a/KeyboardHelper.xcodeproj/project.pbxproj +++ b/KeyboardHelper.xcodeproj/project.pbxproj @@ -184,7 +184,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0720; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = Nodes; TargetAttributes = { 275BCA761C57C9F800FF3647 = { @@ -364,7 +364,7 @@ SKIP_INSTALL = YES; SWIFT_OBJC_INTERFACE_HEADER_NAME = "$(SWIFT_MODULE_NAME)-Swift.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 2.3; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -382,7 +382,8 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OBJC_INTERFACE_HEADER_NAME = "$(SWIFT_MODULE_NAME)-Swift.h"; - SWIFT_VERSION = 2.3; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -393,7 +394,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.nodes.KeyboardHelperTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 2.3; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -404,7 +405,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.nodes.KeyboardHelperTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 2.3; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/KeyboardHelper.xcodeproj/xcshareddata/xcschemes/KeyboardHelper.xcscheme b/KeyboardHelper.xcodeproj/xcshareddata/xcschemes/KeyboardHelper.xcscheme index 705b012..d542d9d 100644 --- a/KeyboardHelper.xcodeproj/xcshareddata/xcschemes/KeyboardHelper.xcscheme +++ b/KeyboardHelper.xcodeproj/xcshareddata/xcschemes/KeyboardHelper.xcscheme @@ -1,6 +1,6 @@ Void, completion: (finished: Bool) -> Void) { - UIView.animateWithDuration( - animationDuration, + public func animateAlong(_ animationBlock: () -> Void, completion: (finished: Bool) -> Void) { + UIView.animate( + withDuration: animationDuration, delay: 0.0, options: animationOptions, animations: animationBlock, completion: completion )} -} \ No newline at end of file +} diff --git a/KeyboardHelper/Classes/KeyboardHelper.swift b/KeyboardHelper/Classes/KeyboardHelper.swift index f1e0210..fb207ea 100644 --- a/KeyboardHelper/Classes/KeyboardHelper.swift +++ b/KeyboardHelper/Classes/KeyboardHelper.swift @@ -2,7 +2,7 @@ // KeyboardHelper.swift // KeyboardHelper // -// Created by Timmi Trinks on 27/01/16. +// Created by Kasper Welner on 27/01/16. // Copyright © 2016 Nodes. All rights reserved. // @@ -19,13 +19,13 @@ public protocol KeyboardNotificationDelegate: class { This function will recongnize a change of `KeyboardAppearanceInfo` and will be fired when the keyboard will appaear. - Parameter info: Struct `KeyboardAppearanceInfo`. */ - func keyboardWillAppear(info: KeyboardAppearanceInfo) + func keyboardWillAppear(_ info: KeyboardAppearanceInfo) /** This function will recongnize a change of `KeyboardAppearanceInfo` and will be fired when the keyboard will disappaear. - Parameter info: Struct `KeyboardAppearanceInfo`. */ - func keyboardWillDisappear(info: KeyboardAppearanceInfo) + func keyboardWillDisappear(_ info: KeyboardAppearanceInfo) } /** @@ -45,25 +45,25 @@ public class KeyboardHelper { required public init(delegate: KeyboardNotificationDelegate) { self.delegate = delegate - NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(KeyboardHelper.keyboardWillAppear(_:)), name: UIKeyboardWillShowNotification, object: nil) - NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(KeyboardHelper.keyboardWillDisappear(_:)), name: UIKeyboardWillHideNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(KeyboardHelper.keyboardWillAppear(_:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(KeyboardHelper.keyboardWillDisappear(_:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil) } private init() { delegate = nil } - dynamic private func keyboardWillAppear(note: NSNotification) { + dynamic private func keyboardWillAppear(_ note: Notification) { let info = KeyboardAppearanceInfo(notification: note) self.delegate?.keyboardWillAppear(info) } - dynamic private func keyboardWillDisappear(note: NSNotification) { + dynamic private func keyboardWillDisappear(_ note: Notification) { let info = KeyboardAppearanceInfo(notification: note) self.delegate?.keyboardWillDisappear(info) } deinit { - NSNotificationCenter.defaultCenter().removeObserver(self) + NotificationCenter.default.removeObserver(self) } } diff --git a/KeyboardHelperTests/Tests/KeyboardAppearanceInfoTests.swift b/KeyboardHelperTests/Tests/KeyboardAppearanceInfoTests.swift index ee1c57a..b36dffb 100644 --- a/KeyboardHelperTests/Tests/KeyboardAppearanceInfoTests.swift +++ b/KeyboardHelperTests/Tests/KeyboardAppearanceInfoTests.swift @@ -18,11 +18,11 @@ class KeyboardAppearanceInfoTests: XCTestCase { super.setUp() // Create test info - var testUserInfo: [String: AnyObject] = [ - UIKeyboardFrameBeginUserInfoKey: NSValue(CGRect: CGRect(x: 100, y: 100, width: 100, height: 100)), - UIKeyboardFrameEndUserInfoKey: NSValue(CGRect: CGRect(x: 200, y: 200, width: 200, height: 200)), + var testUserInfo: [String: Any] = [ + UIKeyboardFrameBeginUserInfoKey: NSValue(cgRect: CGRect(x: 100, y: 100, width: 100, height: 100)), + UIKeyboardFrameEndUserInfoKey: NSValue(cgRect: CGRect(x: 200, y: 200, width: 200, height: 200)), UIKeyboardAnimationDurationUserInfoKey: 3.0, - UIKeyboardAnimationCurveUserInfoKey: UIViewAnimationCurve.EaseOut.rawValue, + UIKeyboardAnimationCurveUserInfoKey: NSNumber(integerLiteral: UIViewAnimationCurve.easeOut.rawValue), ] if #available(iOS 9.0, *) { @@ -32,23 +32,23 @@ class KeyboardAppearanceInfoTests: XCTestCase { } // Fake the notification - let note = NSNotification(name: UIKeyboardWillShowNotification, object: nil, userInfo: testUserInfo) + let note = Notification(name: NSNotification.Name.UIKeyboardWillShow, object: nil, userInfo: testUserInfo) apperanceInfo = KeyboardAppearanceInfo(notification: note) - let defaultNote = NSNotification(name: UIKeyboardWillShowNotification, object: nil, userInfo: nil) + let defaultNote = Notification(name: NSNotification.Name.UIKeyboardWillShow, object: nil, userInfo: nil) defaultsAppearanceInfo = KeyboardAppearanceInfo(notification: defaultNote) } func testBeginFrame() { XCTAssertEqual(apperanceInfo.beginFrame, CGRect(x: 100, y: 100, width: 100, height: 100), "Parsing beginFrame from keyboard appearance info failed.") - XCTAssertEqual(defaultsAppearanceInfo.beginFrame, CGRectZero, + XCTAssertEqual(defaultsAppearanceInfo.beginFrame, CGRect.zero, "Parsing default beginFrame from keyboard appearance info failed.") } func testEndFrame() { XCTAssertEqual(apperanceInfo.endFrame, CGRect(x: 200, y: 200, width: 200, height: 200), "Parsing endFrame from keyboard appearance info failed.") - XCTAssertEqual(defaultsAppearanceInfo.endFrame, CGRectZero, + XCTAssertEqual(defaultsAppearanceInfo.endFrame, CGRect.zero, "Parsing default endFrame from keyboard appearance info failed.") } @@ -75,7 +75,7 @@ class KeyboardAppearanceInfoTests: XCTestCase { } func testAnimateAlong() { - let expectation = expectationWithDescription("Animate along should take 3 seconds") + let expectation = self.expectation(withDescription: "Animate along should take 3 seconds") apperanceInfo.animateAlong({ () -> Void in // Do animations @@ -85,7 +85,7 @@ class KeyboardAppearanceInfoTests: XCTestCase { } } - waitForExpectationsWithTimeout(3.005, handler: nil) + waitForExpectations(withTimeout: 3.005, handler: nil) } } diff --git a/KeyboardHelperTests/Tests/KeyboardHelperTests.swift b/KeyboardHelperTests/Tests/KeyboardHelperTests.swift index 759685d..40d10d5 100644 --- a/KeyboardHelperTests/Tests/KeyboardHelperTests.swift +++ b/KeyboardHelperTests/Tests/KeyboardHelperTests.swift @@ -14,11 +14,11 @@ class ShowSpyDelegate : KeyboardNotificationDelegate { var expectation : XCTestExpectation? - func keyboardWillDisappear(info: KeyboardAppearanceInfo) { + func keyboardWillDisappear(_ info: KeyboardAppearanceInfo) { } - func keyboardWillAppear(info: KeyboardAppearanceInfo) { + func keyboardWillAppear(_ info: KeyboardAppearanceInfo) { guard let expectation = expectation else { XCTFail("ShowSpyDelegate was not setup correctly. Missing XCTExpectation reference") return @@ -34,7 +34,7 @@ class HideSpyDelegate : KeyboardNotificationDelegate { var expectation : XCTestExpectation? - func keyboardWillDisappear(info: KeyboardAppearanceInfo) { + func keyboardWillDisappear(_ info: KeyboardAppearanceInfo) { guard let expectation = expectation else { XCTFail("HideSpyDelegate was not setup correctly. Missing XCTExpectation reference") return @@ -44,7 +44,7 @@ class HideSpyDelegate : KeyboardNotificationDelegate { expectation.fulfill() } - func keyboardWillAppear(info: KeyboardAppearanceInfo) { + func keyboardWillAppear(_ info: KeyboardAppearanceInfo) { } } @@ -55,33 +55,33 @@ class KeyboardHelperTests: XCTestCase { let spyDelegate = ShowSpyDelegate() let kh = KeyboardHelper(delegate: spyDelegate) - let expectation = expectationWithDescription("KeyboardHelper calls the delegate as the result of receiving the show notification") + let expectation = self.expectation(withDescription: "KeyboardHelper calls the delegate as the result of receiving the show notification") spyDelegate.expectation = expectation // NSNotificationCenter.defaultCenter().postNotificationName(UIKeyboardWillShowNotification, object: kh) - let notification : NSNotification + let notification : Notification if #available(iOS 9.0, *) { - notification = NSNotification(name: UIKeyboardWillShowNotification, object: kh, userInfo:[ - UIKeyboardAnimationCurveUserInfoKey : NSNumber(int: 7), - UIKeyboardAnimationDurationUserInfoKey : NSNumber(double: 0.25), - UIKeyboardFrameBeginUserInfoKey : NSValue(CGRect: CGRect(x: 0, y: 667, width: 375, height: 0)), - UIKeyboardFrameEndUserInfoKey : NSValue(CGRect: CGRect(x: 0, y: 409, width: 375, height: 258)), - UIKeyboardIsLocalUserInfoKey : NSNumber(bool: true) + notification = Notification(name: NSNotification.Name.UIKeyboardWillShow, object: kh, userInfo:[ + UIKeyboardAnimationCurveUserInfoKey : NSNumber(value: 7), + UIKeyboardAnimationDurationUserInfoKey : NSNumber(value: 0.25), + UIKeyboardFrameBeginUserInfoKey : NSValue(cgRect: CGRect(x: 0, y: 667, width: 375, height: 0)), + UIKeyboardFrameEndUserInfoKey : NSValue(cgRect: CGRect(x: 0, y: 409, width: 375, height: 258)), + UIKeyboardIsLocalUserInfoKey : NSNumber(value: true) ]) } else { - notification = NSNotification(name: UIKeyboardWillShowNotification, object: nil, userInfo:[ - UIKeyboardAnimationCurveUserInfoKey : NSNumber(int: 7), - UIKeyboardAnimationDurationUserInfoKey : NSNumber(double: 0.25), - UIKeyboardFrameBeginUserInfoKey : NSValue(CGRect: CGRect(x: 0, y: 667, width: 375, height: 0)), - UIKeyboardFrameEndUserInfoKey : NSValue(CGRect: CGRect(x: 0, y: 409, width: 375, height: 258)) + notification = Notification(name: NSNotification.Name.UIKeyboardWillShow, object: nil, userInfo:[ + UIKeyboardAnimationCurveUserInfoKey : NSNumber(value: 7), + UIKeyboardAnimationDurationUserInfoKey : NSNumber(value: 0.25), + UIKeyboardFrameBeginUserInfoKey : NSValue(cgRect: CGRect(x: 0, y: 667, width: 375, height: 0)), + UIKeyboardFrameEndUserInfoKey : NSValue(cgRect: CGRect(x: 0, y: 409, width: 375, height: 258)) ]) } - NSNotificationCenter.defaultCenter().postNotification(notification) + NotificationCenter.default.post(notification) - waitForExpectationsWithTimeout(1) { error in + waitForExpectations(withTimeout: 1) { error in if let error = error { XCTFail("waitForExpectationsWithTimeout errored: \(error)") } @@ -104,13 +104,13 @@ class KeyboardHelperTests: XCTestCase { let spyDelegate = HideSpyDelegate() let kh = KeyboardHelper(delegate: spyDelegate) - let expectation = expectationWithDescription("KeyboardHelper calls the delegate as the result of receiving the hide notification") + let expectation = self.expectation(withDescription: "KeyboardHelper calls the delegate as the result of receiving the hide notification") spyDelegate.expectation = expectation - NSNotificationCenter.defaultCenter().postNotificationName(UIKeyboardWillHideNotification, object: kh) + NotificationCenter.default.post(name: NSNotification.Name.UIKeyboardWillHide, object: kh) - waitForExpectationsWithTimeout(1) { error in + waitForExpectations(withTimeout: 1) { error in if let error = error { XCTFail("waitForExpectationsWithTimeout errored: \(error)") } From d7a5a652aee1022fd90b1e6cbc66d6f0213ad2d4 Mon Sep 17 00:00:00 2001 From: Dominik Hadl Date: Tue, 9 Aug 2016 12:04:11 +0200 Subject: [PATCH 2/8] Update tests to Swift 3.0 in Xcode 8 beta 4 --- .../Tests/KeyboardAppearanceInfoTests.swift | 4 ++-- KeyboardHelperTests/Tests/KeyboardHelperTests.swift | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/KeyboardHelperTests/Tests/KeyboardAppearanceInfoTests.swift b/KeyboardHelperTests/Tests/KeyboardAppearanceInfoTests.swift index b36dffb..8f128b0 100644 --- a/KeyboardHelperTests/Tests/KeyboardAppearanceInfoTests.swift +++ b/KeyboardHelperTests/Tests/KeyboardAppearanceInfoTests.swift @@ -75,7 +75,7 @@ class KeyboardAppearanceInfoTests: XCTestCase { } func testAnimateAlong() { - let expectation = self.expectation(withDescription: "Animate along should take 3 seconds") + let expectation = self.expectation(description: "Animate along should take 3 seconds") apperanceInfo.animateAlong({ () -> Void in // Do animations @@ -85,7 +85,7 @@ class KeyboardAppearanceInfoTests: XCTestCase { } } - waitForExpectations(withTimeout: 3.005, handler: nil) + waitForExpectations(timeout: 3.005, handler: nil) } } diff --git a/KeyboardHelperTests/Tests/KeyboardHelperTests.swift b/KeyboardHelperTests/Tests/KeyboardHelperTests.swift index 40d10d5..1d24763 100644 --- a/KeyboardHelperTests/Tests/KeyboardHelperTests.swift +++ b/KeyboardHelperTests/Tests/KeyboardHelperTests.swift @@ -55,7 +55,7 @@ class KeyboardHelperTests: XCTestCase { let spyDelegate = ShowSpyDelegate() let kh = KeyboardHelper(delegate: spyDelegate) - let expectation = self.expectation(withDescription: "KeyboardHelper calls the delegate as the result of receiving the show notification") + let expectation = self.expectation(description: "KeyboardHelper calls the delegate as the result of receiving the show notification") spyDelegate.expectation = expectation // NSNotificationCenter.defaultCenter().postNotificationName(UIKeyboardWillShowNotification, object: kh) @@ -81,7 +81,7 @@ class KeyboardHelperTests: XCTestCase { - waitForExpectations(withTimeout: 1) { error in + waitForExpectations(timeout: 1) { error in if let error = error { XCTFail("waitForExpectationsWithTimeout errored: \(error)") } @@ -104,13 +104,13 @@ class KeyboardHelperTests: XCTestCase { let spyDelegate = HideSpyDelegate() let kh = KeyboardHelper(delegate: spyDelegate) - let expectation = self.expectation(withDescription: "KeyboardHelper calls the delegate as the result of receiving the hide notification") + let expectation = self.expectation(description: "KeyboardHelper calls the delegate as the result of receiving the hide notification") spyDelegate.expectation = expectation NotificationCenter.default.post(name: NSNotification.Name.UIKeyboardWillHide, object: kh) - waitForExpectations(withTimeout: 1) { error in + waitForExpectations(timeout: 1) { error in if let error = error { XCTFail("waitForExpectationsWithTimeout errored: \(error)") } From 523dce2904ec88d47ff51c3f8e0e7ce7a7e98c20 Mon Sep 17 00:00:00 2001 From: Chris Combs Date: Tue, 16 Aug 2016 13:27:04 +0200 Subject: [PATCH 3/8] updated to beta 6 --- .../Classes/KeyboardAppearanceInfo.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/KeyboardHelper/Classes/KeyboardAppearanceInfo.swift b/KeyboardHelper/Classes/KeyboardAppearanceInfo.swift index d2eedd3..6dd86f5 100644 --- a/KeyboardHelper/Classes/KeyboardAppearanceInfo.swift +++ b/KeyboardHelper/Classes/KeyboardAppearanceInfo.swift @@ -15,11 +15,11 @@ import UIKit public struct KeyboardAppearanceInfo { public let notification: Notification - public let userInfo: [NSObject: AnyObject] + public let userInfo: [AnyHashable: Any] public init(notification: Notification) { self.notification = notification - self.userInfo = (notification as NSNotification).userInfo ?? [:] + self.userInfo = notification.userInfo ?? [:] } /** @@ -27,7 +27,7 @@ public struct KeyboardAppearanceInfo { Return a `CGRect` or `CGRectZero`. */ public var beginFrame: CGRect { - return userInfo[UIKeyboardFrameBeginUserInfoKey]?.cgRectValue ?? CGRect.zero + return (userInfo[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue ?? .zero } /** @@ -35,7 +35,7 @@ public struct KeyboardAppearanceInfo { Return a `CGRect` or `CGRectZero`. */ public var endFrame: CGRect { - return userInfo[UIKeyboardFrameEndUserInfoKey]?.cgRectValue ?? CGRect.zero + return (userInfo[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue ?? .zero } /** @@ -45,7 +45,7 @@ public struct KeyboardAppearanceInfo { */ public var belongsToCurrentApp: Bool { if #available(iOS 9.0, *) { - return userInfo[UIKeyboardIsLocalUserInfoKey]?.boolValue ?? true + return (userInfo[UIKeyboardIsLocalUserInfoKey] as? NSString)?.boolValue ?? true } else { return true } @@ -56,7 +56,7 @@ public struct KeyboardAppearanceInfo { By default: `0.25`. */ public var animationDuration: Double { - return userInfo[UIKeyboardAnimationDurationUserInfoKey]?.doubleValue ?? 0.25 + return (userInfo[UIKeyboardAnimationDurationUserInfoKey] as? NSString)?.doubleValue ?? 0.25 } /** @@ -84,7 +84,7 @@ public struct KeyboardAppearanceInfo { - animationBlock: Animation that should happen. - completion: Function that happens after the animation is finished. */ - public func animateAlong(_ animationBlock: () -> Void, completion: (finished: Bool) -> Void) { + public func animateAlong(_ animationBlock: @escaping () -> Void, completion: @escaping (_ finished: Bool) -> Void) { UIView.animate( withDuration: animationDuration, delay: 0.0, From f69e747d5e74c5f9880ac8b0781a3f6e4bd320e9 Mon Sep 17 00:00:00 2001 From: Marius Constantinescu Date: Thu, 3 Nov 2016 16:41:07 +0100 Subject: [PATCH 4/8] Fixed so that tests would pass --- .../Classes/KeyboardAppearanceInfo.swift | 6 +++--- .../Tests/KeyboardAppearanceInfoTests.swift | 17 +++++++++-------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/KeyboardHelper/Classes/KeyboardAppearanceInfo.swift b/KeyboardHelper/Classes/KeyboardAppearanceInfo.swift index 6dd86f5..d0c181f 100644 --- a/KeyboardHelper/Classes/KeyboardAppearanceInfo.swift +++ b/KeyboardHelper/Classes/KeyboardAppearanceInfo.swift @@ -35,7 +35,7 @@ public struct KeyboardAppearanceInfo { Return a `CGRect` or `CGRectZero`. */ public var endFrame: CGRect { - return (userInfo[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue ?? .zero + return (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue ?? .zero } /** @@ -45,7 +45,7 @@ public struct KeyboardAppearanceInfo { */ public var belongsToCurrentApp: Bool { if #available(iOS 9.0, *) { - return (userInfo[UIKeyboardIsLocalUserInfoKey] as? NSString)?.boolValue ?? true + return (userInfo[UIKeyboardIsLocalUserInfoKey] as? Bool) ?? true } else { return true } @@ -56,7 +56,7 @@ public struct KeyboardAppearanceInfo { By default: `0.25`. */ public var animationDuration: Double { - return (userInfo[UIKeyboardAnimationDurationUserInfoKey] as? NSString)?.doubleValue ?? 0.25 + return (userInfo[UIKeyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue ?? 0.25 } /** diff --git a/KeyboardHelperTests/Tests/KeyboardAppearanceInfoTests.swift b/KeyboardHelperTests/Tests/KeyboardAppearanceInfoTests.swift index 8f128b0..3f732cd 100644 --- a/KeyboardHelperTests/Tests/KeyboardAppearanceInfoTests.swift +++ b/KeyboardHelperTests/Tests/KeyboardAppearanceInfoTests.swift @@ -11,7 +11,7 @@ import KeyboardHelper class KeyboardAppearanceInfoTests: XCTestCase { - var apperanceInfo: KeyboardAppearanceInfo! + var appearanceInfo: KeyboardAppearanceInfo! var defaultsAppearanceInfo : KeyboardAppearanceInfo! override func setUp() { @@ -33,20 +33,20 @@ class KeyboardAppearanceInfoTests: XCTestCase { // Fake the notification let note = Notification(name: NSNotification.Name.UIKeyboardWillShow, object: nil, userInfo: testUserInfo) - apperanceInfo = KeyboardAppearanceInfo(notification: note) + appearanceInfo = KeyboardAppearanceInfo(notification: note) let defaultNote = Notification(name: NSNotification.Name.UIKeyboardWillShow, object: nil, userInfo: nil) defaultsAppearanceInfo = KeyboardAppearanceInfo(notification: defaultNote) } func testBeginFrame() { - XCTAssertEqual(apperanceInfo.beginFrame, CGRect(x: 100, y: 100, width: 100, height: 100), + XCTAssertEqual(appearanceInfo.beginFrame, CGRect(x: 100, y: 100, width: 100, height: 100), "Parsing beginFrame from keyboard appearance info failed.") XCTAssertEqual(defaultsAppearanceInfo.beginFrame, CGRect.zero, "Parsing default beginFrame from keyboard appearance info failed.") } func testEndFrame() { - XCTAssertEqual(apperanceInfo.endFrame, CGRect(x: 200, y: 200, width: 200, height: 200), + XCTAssertEqual(appearanceInfo.endFrame, CGRect(x: 200, y: 200, width: 200, height: 200), "Parsing endFrame from keyboard appearance info failed.") XCTAssertEqual(defaultsAppearanceInfo.endFrame, CGRect.zero, "Parsing default endFrame from keyboard appearance info failed.") @@ -54,21 +54,22 @@ class KeyboardAppearanceInfoTests: XCTestCase { @available(iOS 9.0, *) func testBelongsToCurrentApp() { - XCTAssertEqual(apperanceInfo.belongsToCurrentApp, false, + XCTAssertEqual(appearanceInfo.belongsToCurrentApp, false, "Parsing belongsToCurrentApp from keyboard appearance info failed.") XCTAssertEqual(defaultsAppearanceInfo.belongsToCurrentApp, true, "Parsing default belongsToCurrentApp from keyboard appearance info failed.") } func testAnimationDuration() { - XCTAssertEqual(apperanceInfo.animationDuration, Double(3), + + XCTAssertEqual(appearanceInfo.animationDuration, Double(3), "Parsing animationDuration from keyboard appearance info failed.") XCTAssertEqual(defaultsAppearanceInfo.animationDuration, Double(0.25), "Parsing default animationDuration from keyboard appearance info failed.") } func testAnimationCurve() { - XCTAssertEqual(apperanceInfo.animationCurve, UIViewAnimationCurve(rawValue: 2), + XCTAssertEqual(appearanceInfo.animationCurve, UIViewAnimationCurve(rawValue: 2), "Parsing animationCurve from keyboard appearance info failed.") XCTAssertEqual(defaultsAppearanceInfo.animationCurve, UIViewAnimationCurve(rawValue: defaultsAppearanceInfo.animationCurve.rawValue), "Parsing default animationCurve from keyboard appearance info failed.") @@ -77,7 +78,7 @@ class KeyboardAppearanceInfoTests: XCTestCase { func testAnimateAlong() { let expectation = self.expectation(description: "Animate along should take 3 seconds") - apperanceInfo.animateAlong({ () -> Void in + appearanceInfo.animateAlong({ () -> Void in // Do animations }) { (finished) -> Void in if finished { From ba56948711ddbf844aef0648fe0c5a5c30e7cd13 Mon Sep 17 00:00:00 2001 From: Marius Constantinescu Date: Mon, 7 Nov 2016 10:06:21 +0100 Subject: [PATCH 5/8] Made completion optional in animateAlong --- KeyboardHelper.xcodeproj/project.pbxproj | 6 +++++- .../xcshareddata/xcschemes/KeyboardHelper.xcscheme | 2 +- KeyboardHelper/Classes/KeyboardAppearanceInfo.swift | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/KeyboardHelper.xcodeproj/project.pbxproj b/KeyboardHelper.xcodeproj/project.pbxproj index 2499261..63f0f48 100644 --- a/KeyboardHelper.xcodeproj/project.pbxproj +++ b/KeyboardHelper.xcodeproj/project.pbxproj @@ -184,7 +184,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0800; + LastUpgradeCheck = 0810; ORGANIZATIONNAME = Nodes; TargetAttributes = { 275BCA761C57C9F800FF3647 = { @@ -275,8 +275,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; @@ -322,8 +324,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; diff --git a/KeyboardHelper.xcodeproj/xcshareddata/xcschemes/KeyboardHelper.xcscheme b/KeyboardHelper.xcodeproj/xcshareddata/xcschemes/KeyboardHelper.xcscheme index d542d9d..747eba5 100644 --- a/KeyboardHelper.xcodeproj/xcshareddata/xcschemes/KeyboardHelper.xcscheme +++ b/KeyboardHelper.xcodeproj/xcshareddata/xcschemes/KeyboardHelper.xcscheme @@ -1,6 +1,6 @@ Void, completion: @escaping (_ finished: Bool) -> Void) { + public func animateAlong(_ animationBlock: @escaping (() -> Void), completion: @escaping ((_ finished: Bool) -> Void) = { _ in }) { UIView.animate( withDuration: animationDuration, delay: 0.0, From e10aefb897d5eff0f2dcd88c7cecef2d0316f413 Mon Sep 17 00:00:00 2001 From: Marius Constantinescu Date: Mon, 7 Nov 2016 15:23:46 +0100 Subject: [PATCH 6/8] Updated README and example project --- Example/Cartfile | 2 +- Example/Cartfile.resolved | 2 +- .../KeyboardHelperDemo.xcodeproj/project.pbxproj | 3 +++ Example/KeyboardHelperDemo/AppDelegate.swift | 12 ++++++------ Example/KeyboardHelperDemo/ViewController.swift | 14 +++++++------- README.md | 12 ++++++------ 6 files changed, 24 insertions(+), 21 deletions(-) diff --git a/Example/Cartfile b/Example/Cartfile index ce636df..72d3802 100644 --- a/Example/Cartfile +++ b/Example/Cartfile @@ -1 +1 @@ -github "nodes-ios/KeyboardHelper" "master" +github "nodes-ios/KeyboardHelper" "swift-3.0" diff --git a/Example/Cartfile.resolved b/Example/Cartfile.resolved index 789ef8f..86a8ee8 100644 --- a/Example/Cartfile.resolved +++ b/Example/Cartfile.resolved @@ -1 +1 @@ -github "nodes-ios/KeyboardHelper" "30ed3728bf10b7d2a606d1e23bb23c12eea02222" +github "nodes-ios/KeyboardHelper" "58d7c2bf19f7bc93d733290f06ae0eedf03f18a5" diff --git a/Example/KeyboardHelperDemo.xcodeproj/project.pbxproj b/Example/KeyboardHelperDemo.xcodeproj/project.pbxproj index ac19532..476327e 100644 --- a/Example/KeyboardHelperDemo.xcodeproj/project.pbxproj +++ b/Example/KeyboardHelperDemo.xcodeproj/project.pbxproj @@ -128,6 +128,7 @@ TargetAttributes = { 29F30E661C807E2A00C77AF4 = { CreatedOnToolsVersion = 7.2; + LastSwiftMigration = 0810; }; }; }; @@ -289,6 +290,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = dk.nodes.KeyboardHelperDemo; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -305,6 +307,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = dk.nodes.KeyboardHelperDemo; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/Example/KeyboardHelperDemo/AppDelegate.swift b/Example/KeyboardHelperDemo/AppDelegate.swift index 71b67b3..163cf7b 100644 --- a/Example/KeyboardHelperDemo/AppDelegate.swift +++ b/Example/KeyboardHelperDemo/AppDelegate.swift @@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return true } - func applicationWillResignActive(application: UIApplication) { + func applicationWillResignActive(_ application: UIApplication) { // 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. // 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. } - func applicationDidEnterBackground(application: UIApplication) { + func applicationDidEnterBackground(_ application: UIApplication) { // 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. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - func applicationWillEnterForeground(application: UIApplication) { + func applicationWillEnterForeground(_ application: UIApplication) { // 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. } - func applicationDidBecomeActive(application: UIApplication) { + func applicationDidBecomeActive(_ application: UIApplication) { // 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. } - func applicationWillTerminate(application: UIApplication) { + func applicationWillTerminate(_ application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } diff --git a/Example/KeyboardHelperDemo/ViewController.swift b/Example/KeyboardHelperDemo/ViewController.swift index b6b18bd..862f164 100644 --- a/Example/KeyboardHelperDemo/ViewController.swift +++ b/Example/KeyboardHelperDemo/ViewController.swift @@ -11,8 +11,8 @@ import KeyboardHelper class ViewController: UIViewController, KeyboardNotificationDelegate { - private var tapGesture: UITapGestureRecognizer! - private var keyboardHelper : KeyboardHelper? + fileprivate var tapGesture: UITapGestureRecognizer! + fileprivate var keyboardHelper : KeyboardHelper? @IBOutlet weak var scrollView: UIScrollView! override func viewDidLoad() { @@ -21,7 +21,7 @@ class ViewController: UIViewController, KeyboardNotificationDelegate { self.tapGesture = UITapGestureRecognizer(target: self, action: #selector(ViewController.dismissKeyboard)) self.view.addGestureRecognizer(tapGesture) - self.tapGesture.enabled = true + self.tapGesture.isEnabled = true self.keyboardHelper = KeyboardHelper(delegate: self) } @@ -30,7 +30,7 @@ class ViewController: UIViewController, KeyboardNotificationDelegate { self.view.endEditing(true) } - func keyboardWillAppear(info: KeyboardAppearanceInfo) { + func keyboardWillAppear(_ info: KeyboardAppearanceInfo) { info.animateAlong({ () -> Void in let insets = UIEdgeInsetsMake(0, 0, info.endFrame.size.height, 0) self.scrollView.contentInset = insets @@ -38,12 +38,12 @@ class ViewController: UIViewController, KeyboardNotificationDelegate { }) { finished in } } - func keyboardWillDisappear(info: KeyboardAppearanceInfo) { - UIView.animateWithDuration(NSTimeInterval(info.animationDuration), + func keyboardWillDisappear(_ info: KeyboardAppearanceInfo) { + UIView.animate(withDuration: TimeInterval(info.animationDuration), delay: 0, options: info.animationOptions, animations: { - let insets = UIEdgeInsetsZero + let insets = UIEdgeInsets.zero self.scrollView.contentInset = insets self.scrollView.scrollIndicatorInsets = insets }, diff --git a/README.md b/README.md index b6574fd..71fcae6 100644 --- a/README.md +++ b/README.md @@ -57,8 +57,8 @@ self.keyboardHelper = KeyboardHelper(delegate: self) Implement the two methods in the `KeyboardNotificationDelegate`: ```swift -public func keyboardWillAppear(info: KeyboardHelper.KeyboardAppearanceInfo) -public func keyboardWillDisappear(info: KeyboardHelper.KeyboardAppearanceInfo) +public func keyboardWillAppear(_ info: KeyboardHelper.KeyboardAppearanceInfo) +public func keyboardWillDisappear(_ info: KeyboardHelper.KeyboardAppearanceInfo) ``` Both methods take as argument a `KeyboardAppearanceInfo` object, which is basically a wrapper over the `userInfo` dictionary of the `UIKeyboardWillShowNotification` and `UIKeyboardWillHideNotification` notifications. @@ -66,8 +66,8 @@ Both methods take as argument a `KeyboardAppearanceInfo` object, which is basica One example of implementation for the two delegate methods is: ```swift -func keyboardWillAppear(info: KeyboardAppearanceInfo) { - UIView.animateWithDuration(NSTimeInterval(info.animationDuration), +func keyboardWillAppear(_ info: KeyboardAppearanceInfo) { + UIView.animate(withDuration: TimeInterval(info.animationDuration), delay: 0, options: info.animationOptions, animations: { @@ -78,8 +78,8 @@ func keyboardWillAppear(info: KeyboardAppearanceInfo) { completion:nil) } - func keyboardWillDisappear(info: KeyboardAppearanceInfo) { - UIView.animateWithDuration(NSTimeInterval(info.animationDuration), + func keyboardWillDisappear(_ info: KeyboardAppearanceInfo) { + UIView.animate(withDuration: TimeInterval(info.animationDuration), delay: 0, options: info.animationOptions, animations: { From 8902f82acaba2773c386ae188cab96eaf1b9043b Mon Sep 17 00:00:00 2001 From: Dominik Hadl Date: Wed, 14 Dec 2016 21:41:00 +0000 Subject: [PATCH 7/8] Mention versions in README --- README.md | 61 ++++++++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 71fcae6..26ab920 100644 --- a/README.md +++ b/README.md @@ -15,30 +15,23 @@ A small (but cool) tool for handling UIKeyboard appearing and disappearing in yo ## 📦 Installation ### Carthage +~~~bash +github "nodes-ios/KeyboardHelper" ~> 1.0 ~~~ -github "nodes-ios/KeyboardHelper" -~~~ + +> Last versions compatible with lower Swift versions: +> +> **Swift 2.3** +> `github "nodes-ios/KeyboardHelper" == 0.10.0` +> +> **Swift 2.2** +> `github "nodes-ios/KeyboardHelper" == 0.9.4` ### CocoaPods ~~~ -pod 'KeyboardHelper', '~> 0.9' +pod 'KeyboardHelper', '~> 1.0' ~~~ -### Swit Package Manager -To use KeyboardHelper as a [Swift Package Manager](https://swift.org/package-manager/) package just add the following to your `Package.swift` file. - -~~~swift -import PackageDescription - -let package = Package( - name: "YourPackage", - dependencies: [ - .Package(url: "https://github.com/nodes-ios/KeyboardHelper.git", majorVersion: 0) - ] -) -~~~ - -**NOTE:** This doesn't currently work as SPM doesn't support iOS, but once it will we will already be supporting it! :) ## 🔧 Setup Implement `KeyboardNotificationDelegate` in your UIViewController. @@ -47,12 +40,16 @@ Implement `KeyboardNotificationDelegate` in your UIViewController. class ViewController: UIViewController, KeyboardNotificationDelegate ``` -Add a `KeyboardHelper` private variable and initialize it, setting the delegate. +Add a `KeyboardHelper` private variable, initialize it and set the delegate. ```swift private var keyboardHelper : KeyboardHelper? -... -self.keyboardHelper = KeyboardHelper(delegate: self) + +func viewDidLoad() { + ... + self.keyboardHelper = KeyboardHelper(delegate: self) + ... +} ``` Implement the two methods in the `KeyboardNotificationDelegate`: @@ -78,17 +75,17 @@ func keyboardWillAppear(_ info: KeyboardAppearanceInfo) { completion:nil) } - func keyboardWillDisappear(_ info: KeyboardAppearanceInfo) { - UIView.animate(withDuration: TimeInterval(info.animationDuration), - delay: 0, - options: info.animationOptions, - animations: { - let insets = UIEdgeInsetsZero - self.scrollView.contentInset = insets - self.scrollView.scrollIndicatorInsets = insets - }, - completion:nil) - } +func keyboardWillDisappear(_ info: KeyboardAppearanceInfo) { + UIView.animate(withDuration: TimeInterval(info.animationDuration), + delay: 0, + options: info.animationOptions, + animations: { + let insets = UIEdgeInsetsZero + self.scrollView.contentInset = insets + self.scrollView.scrollIndicatorInsets = insets + }, + completion:nil) +} ``` The `KeyboardAppearanceInfo` object has the following properties: From 29108a0472ed7cf78e90a1c6d9f8a737f1e360a2 Mon Sep 17 00:00:00 2001 From: Dominik Hadl Date: Wed, 14 Dec 2016 21:41:45 +0000 Subject: [PATCH 8/8] Update podspec --- KeyboardHelper.podspec | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/KeyboardHelper.podspec b/KeyboardHelper.podspec index 6fb2605..acaf117 100644 --- a/KeyboardHelper.podspec +++ b/KeyboardHelper.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |s| # s.name = "KeyboardHelper" - s.version = "0.9.2" + s.version = "1.0.0" s.summary = "Handle UIKeyboard with ease, delegation and strongly typed user info included!" # This description is used to generate tags and improve search results. @@ -66,7 +66,7 @@ Pod::Spec.new do |s| # s.platform = :ios, "5.0" # When using multiple platforms - s.ios.deployment_target = "8.1" + s.ios.deployment_target = "8.0" # s.osx.deployment_target = "10.7" # s.watchos.deployment_target = "2.0" # s.tvos.deployment_target = "9.0" @@ -78,7 +78,7 @@ Pod::Spec.new do |s| # Supports git, hg, bzr, svn and HTTP. # - s.source = { :git => "https://github.com/nodes-ios/KeyboardHelper.git", :tag => "0.9.2" } + s.source = { :git => "https://github.com/nodes-ios/KeyboardHelper.git", :tag => s.version } # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # @@ -134,4 +134,3 @@ Pod::Spec.new do |s| # s.dependency "JSONKit", "~> 1.4" end -