Skip to content

Commit 0c19e9d

Browse files
committed
Update code for Swift 4.2 / Xcode 10
1 parent eaee342 commit 0c19e9d

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:4.1
1+
// swift-tools-version:4.2
22

33
import PackageDescription
44

@@ -8,7 +8,7 @@ let package = Package(
88
.library(name: "RxKeyboard", targets: ["RxKeyboard"]),
99
],
1010
dependencies: [
11-
.package(url: "https://github.com/ReactiveX/RxSwift.git", .upToNextMajor(from: "4.1.0")),
11+
.package(url: "https://github.com/ReactiveX/RxSwift.git", .upToNextMajor(from: "4.3.0")),
1212
],
1313
targets: [
1414
.target(name: "RxKeyboard", dependencies: ["RxSwift", "RxCocoa"]),

Sources/RxKeyboard/RxKeyboard.swift

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,21 @@ public class RxKeyboard: NSObject, RxKeyboardType {
4747
private let disposeBag = DisposeBag()
4848
private let panRecognizer = UIPanGestureRecognizer()
4949

50-
5150
// MARK: Initializing
5251

5352
override init() {
53+
#if swift(>=4.2)
54+
let keyboardWillChangeFrame = UIResponder.keyboardWillChangeFrameNotification
55+
let keyboardWillHide = UIResponder.keyboardWillHideNotification
56+
let keyboardFrameEndKey = UIResponder.keyboardFrameEndUserInfoKey
57+
let applicationDidFinishLaunching = UIApplication.didFinishLaunchingNotification
58+
#else
59+
let keyboardWillChangeFrame = NSNotification.Name.UIKeyboardWillChangeFrame
60+
let keyboardWillHide = NSNotification.Name.UIKeyboardWillHide
61+
let keyboardFrameEndKey = UIKeyboardFrameEndUserInfoKey
62+
let applicationDidFinishLaunching = NSNotification.Name.UIApplicationDidFinishLaunching
63+
#endif
64+
5465
let defaultFrame = CGRect(
5566
x: 0,
5667
y: UIScreen.main.bounds.height,
@@ -70,9 +81,9 @@ public class RxKeyboard: NSObject, RxKeyboardType {
7081
super.init()
7182

7283
// keyboard will change frame
73-
let willChangeFrame = NotificationCenter.default.rx.notification(.UIKeyboardWillChangeFrame)
84+
let willChangeFrame = NotificationCenter.default.rx.notification(keyboardWillChangeFrame)
7485
.map { notification -> CGRect in
75-
let rectValue = notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue
86+
let rectValue = notification.userInfo?[keyboardFrameEndKey] as? NSValue
7687
return rectValue?.cgRectValue ?? defaultFrame
7788
}
7889
.map { frame -> CGRect in
@@ -85,9 +96,9 @@ public class RxKeyboard: NSObject, RxKeyboardType {
8596
}
8697

8798
// keyboard will hide
88-
let willHide = NotificationCenter.default.rx.notification(.UIKeyboardWillHide)
99+
let willHide = NotificationCenter.default.rx.notification(keyboardWillHide)
89100
.map { notification -> CGRect in
90-
let rectValue = notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue
101+
let rectValue = notification.userInfo?[keyboardFrameEndKey] as? NSValue
91102
return rectValue?.cgRectValue ?? defaultFrame
92103
}
93104
.map { frame -> CGRect in
@@ -120,7 +131,7 @@ public class RxKeyboard: NSObject, RxKeyboardType {
120131

121132
// gesture recognizer
122133
self.panRecognizer.delegate = self
123-
NotificationCenter.default.rx.notification(.UIApplicationDidFinishLaunching)
134+
NotificationCenter.default.rx.notification(applicationDidFinishLaunching)
124135
.map { _ in Void() }
125136
.startWith(Void()) // when RxKeyboard is initialized before UIApplication.window is created
126137
.subscribe(onNext: { _ in

0 commit comments

Comments
 (0)