Skip to content

Commit 2939edd

Browse files
author
Bell App Lab
committed
Swift 4.2
1 parent 8269e18 commit 2939edd

File tree

6 files changed

+48
-35
lines changed

6 files changed

+48
-35
lines changed

Example/Example.xcodeproj/project.pbxproj

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -156,22 +156,6 @@
156156
path = Keyboard;
157157
sourceTree = "<group>";
158158
};
159-
65C83F6420FCDCE7004F5620 /* Tests */ = {
160-
isa = PBXGroup;
161-
children = (
162-
65C83F6520FCDCE7004F5620 /* KeyboardTests */,
163-
);
164-
name = Tests;
165-
path = ../Tests;
166-
sourceTree = "<group>";
167-
};
168-
65C83F6520FCDCE7004F5620 /* KeyboardTests */ = {
169-
isa = PBXGroup;
170-
children = (
171-
);
172-
path = KeyboardTests;
173-
sourceTree = "<group>";
174-
};
175159
65C83F6B20FCDD37004F5620 /* iOS Example */ = {
176160
isa = PBXGroup;
177161
children = (
@@ -238,7 +222,6 @@
238222
65C83F9320FCDD56004F5620 /* iOS Tests */,
239223
65C83FA120FCDD5E004F5620 /* iOS UITests */,
240224
65C83F8220FCDD4B004F5620 /* Keyboard_iOS */,
241-
65C83F6420FCDCE7004F5620 /* Tests */,
242225
65E75B4B1DA7DF2F000A44A9 /* Products */,
243226
);
244227
sourceTree = "<group>";
@@ -819,8 +802,8 @@
819802
SDKROOT = iphoneos;
820803
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
821804
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
822-
SWIFT_VERSION = 3.0;
823-
VERSION = 1.0;
805+
SWIFT_VERSION = 3.3;
806+
VERSION = 1.0.1;
824807
};
825808
name = Debug;
826809
};
@@ -872,9 +855,9 @@
872855
PRODUCT_NAME = Keyboard;
873856
SDKROOT = iphoneos;
874857
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
875-
SWIFT_VERSION = 3.0;
858+
SWIFT_VERSION = 3.3;
876859
VALIDATE_PRODUCT = YES;
877-
VERSION = 1.0;
860+
VERSION = 1.0.1;
878861
};
879862
name = Release;
880863
};

Example/iOS Example/AppDelegate.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@ import UIKit
44
@UIApplicationMain
55
class AppDelegate: UIResponder, UIApplicationDelegate
66
{
7-
var window: UIWindow?
7+
var window: UIWindow?
88

9-
func application(_ application: UIApplication,
10-
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
11-
{
12-
return true
13-
}
9+
#if swift(>=4.2)
10+
func application(_ application: UIApplication,
11+
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
12+
{
13+
return true
14+
}
15+
#else
16+
func application(_ application: UIApplication,
17+
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
18+
{
19+
return true
20+
}
21+
#endif
1422
}
1523

Keyboard.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = "Keyboard"
4-
s.version = "1.0.0"
4+
s.version = "1.0.1"
55
s.summary = "Never implement the UIKeyboardDidShow notification ever again. Ever."
66
s.screenshot = "https://github.com/BellAppLab/Keyboard/raw/master/Images/keyboard.png"
77

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ let package = Package(
1212
.target(
1313
name: "Keyboard"
1414
),
15-
],
16-
swiftLanguageVersions: [3, 4]
15+
],
16+
swiftLanguageVersions: [3.3, 4.1, 4.2]
1717
)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# Keyboard [![Version](https://img.shields.io/badge/Version-1.0-black.svg?style=flat)](#installation) [![License](https://img.shields.io/cocoapods/l/Keyboard.svg?style=flat)](#license)
1+
# Keyboard [![Version](https://img.shields.io/badge/Version-1.0.1-black.svg?style=flat)](#installation) [![License](https://img.shields.io/cocoapods/l/Keyboard.svg?style=flat)](#license)
22

33
[![Platforms](https://img.shields.io/badge/Platforms-iOS-brightgreen.svg?style=flat)](#installation)
4-
[![Swift support](https://img.shields.io/badge/Swift-3.3%20%7C%204.1-red.svg?style=flat)](#swift-versions-support)
4+
[![Swift support](https://img.shields.io/badge/Swift-3.3%20%7C%204.1%20%7C%204.2-red.svg?style=flat)](#swift-versions-support)
55
[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/Keyboard.svg?style=flat&label=CocoaPods)](https://cocoapods.org/pods/Keyboard)
66
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
77
[![Swift Package Manager compatible](https://img.shields.io/badge/SPM-compatible-orange.svg?style=flat)](https://github.com/apple/swift-package-manager)

Sources/Keyboard/Notifications+Keyboard.swift

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import UIKit
22

33

4+
#if swift(>=4.2)
5+
public typealias AnimationOptions = UIView.AnimationOptions
6+
#else
7+
public typealias AnimationOptions = UIViewAnimationOptions
8+
#endif
9+
10+
411
//MARK: - MAIN
512
@nonobjc
613
public extension Keyboard {
@@ -14,13 +21,13 @@ public extension Keyboard {
1421
/// The keyboard's transition duration.
1522
public let transitionDuration: Double
1623
/// The keyboard's transition animation options.
17-
public let transitionAnimationOptions: UIViewAnimationOptions
24+
public let transitionAnimationOptions: AnimationOptions
1825

1926
//MARK: - Setup
2027
private init(initialTransitionRect: CGRect,
2128
finalTransitionRect: CGRect,
2229
transitionDuration: Double,
23-
transitionAnimationOptions: UIViewAnimationOptions)
30+
transitionAnimationOptions: AnimationOptions)
2431
{
2532
self.initialTransitionRect = initialTransitionRect
2633
self.finalTransitionRect = finalTransitionRect
@@ -30,12 +37,20 @@ public extension Keyboard {
3037

3138
fileprivate init?(userInfo: [AnyHashable: Any])
3239
{
40+
#if swift(>=4.2)
41+
guard let initialRect = (userInfo[UIResponder.keyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue,
42+
let finalRect = (userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue,
43+
let duration = (userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue,
44+
let options = (userInfo[UIResponder.keyboardAnimationCurveUserInfoKey] as? NSNumber)?.uintValue
45+
else { return nil }
46+
#else
3347
guard let initialRect = (userInfo[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue,
3448
let finalRect = (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue,
3549
let duration = (userInfo[UIKeyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue,
3650
let options = (userInfo[UIKeyboardAnimationCurveUserInfoKey] as? NSNumber)?.uintValue
3751
else { return nil }
38-
let animationOptions = UIViewAnimationOptions(rawValue: options).union(.beginFromCurrentState)
52+
#endif
53+
let animationOptions = AnimationOptions(rawValue: options).union(.beginFromCurrentState)
3954
self.init(initialTransitionRect: initialRect,
4055
finalTransitionRect: finalRect,
4156
transitionDuration: duration,
@@ -154,9 +169,16 @@ fileprivate extension NotificationCenter
154169
//MARK: - Notification + Keyboard Change Handler
155170
fileprivate extension Notification
156171
{
172+
#if swift(>=4.2)
173+
static var allKeyboardNotifications = [
174+
UIResponder.keyboardWillChangeFrameNotification
175+
]
176+
#else
157177
static var allKeyboardNotifications = [
158178
Notification.Name.UIKeyboardWillChangeFrame
159179
]
180+
#endif
181+
160182

161183
var keyboardChange: Keyboard.Change? {
162184
guard Notification.allKeyboardNotifications.contains(name) else { return nil }

0 commit comments

Comments
 (0)