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

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
}

0 commit comments

Comments
 (0)