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

Commit d5e1595

Browse files
author
Dominik Hádl
committed
Update to Swift 5 and fix project warnings
1 parent a34eaff commit d5e1595

6 files changed

Lines changed: 72 additions & 46 deletions

File tree

KeyboardHelper.xcodeproj/project.pbxproj

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,25 +184,26 @@
184184
isa = PBXProject;
185185
attributes = {
186186
LastSwiftUpdateCheck = 0720;
187-
LastUpgradeCheck = 0810;
187+
LastUpgradeCheck = 1020;
188188
ORGANIZATIONNAME = Nodes;
189189
TargetAttributes = {
190190
275BCA761C57C9F800FF3647 = {
191191
CreatedOnToolsVersion = 7.2;
192-
LastSwiftMigration = 0900;
192+
LastSwiftMigration = 1020;
193193
};
194194
275BCA801C57C9F800FF3647 = {
195195
CreatedOnToolsVersion = 7.2;
196-
LastSwiftMigration = 0900;
196+
LastSwiftMigration = 1020;
197197
};
198198
};
199199
};
200200
buildConfigurationList = 275BCA711C57C9F800FF3647 /* Build configuration list for PBXProject "KeyboardHelper" */;
201201
compatibilityVersion = "Xcode 3.2";
202-
developmentRegion = English;
202+
developmentRegion = en;
203203
hasScannedForEncodings = 0;
204204
knownRegions = (
205205
en,
206+
Base,
206207
);
207208
mainGroup = 275BCA6D1C57C9F800FF3647;
208209
productRefGroup = 275BCA781C57C9F800FF3647 /* Products */;
@@ -266,18 +267,27 @@
266267
isa = XCBuildConfiguration;
267268
buildSettings = {
268269
ALWAYS_SEARCH_USER_PATHS = NO;
270+
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
269271
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
270272
CLANG_CXX_LIBRARY = "libc++";
271273
CLANG_ENABLE_MODULES = YES;
272274
CLANG_ENABLE_OBJC_ARC = YES;
275+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
273276
CLANG_WARN_BOOL_CONVERSION = YES;
277+
CLANG_WARN_COMMA = YES;
274278
CLANG_WARN_CONSTANT_CONVERSION = YES;
279+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
275280
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
276281
CLANG_WARN_EMPTY_BODY = YES;
277282
CLANG_WARN_ENUM_CONVERSION = YES;
278283
CLANG_WARN_INFINITE_RECURSION = YES;
279284
CLANG_WARN_INT_CONVERSION = YES;
285+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
286+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
287+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
280288
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
289+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
290+
CLANG_WARN_STRICT_PROTOTYPES = YES;
281291
CLANG_WARN_SUSPICIOUS_MOVE = YES;
282292
CLANG_WARN_UNREACHABLE_CODE = YES;
283293
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -315,18 +325,27 @@
315325
isa = XCBuildConfiguration;
316326
buildSettings = {
317327
ALWAYS_SEARCH_USER_PATHS = NO;
328+
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
318329
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
319330
CLANG_CXX_LIBRARY = "libc++";
320331
CLANG_ENABLE_MODULES = YES;
321332
CLANG_ENABLE_OBJC_ARC = YES;
333+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
322334
CLANG_WARN_BOOL_CONVERSION = YES;
335+
CLANG_WARN_COMMA = YES;
323336
CLANG_WARN_CONSTANT_CONVERSION = YES;
337+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
324338
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
325339
CLANG_WARN_EMPTY_BODY = YES;
326340
CLANG_WARN_ENUM_CONVERSION = YES;
327341
CLANG_WARN_INFINITE_RECURSION = YES;
328342
CLANG_WARN_INT_CONVERSION = YES;
343+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
344+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
345+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
329346
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
347+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
348+
CLANG_WARN_STRICT_PROTOTYPES = YES;
330349
CLANG_WARN_SUSPICIOUS_MOVE = YES;
331350
CLANG_WARN_UNREACHABLE_CODE = YES;
332351
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -368,8 +387,7 @@
368387
SKIP_INSTALL = YES;
369388
SWIFT_OBJC_INTERFACE_HEADER_NAME = "$(SWIFT_MODULE_NAME)-Swift.h";
370389
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
371-
SWIFT_SWIFT3_OBJC_INFERENCE = On;
372-
SWIFT_VERSION = 4.0;
390+
SWIFT_VERSION = 5.0;
373391
};
374392
name = Debug;
375393
};
@@ -388,8 +406,7 @@
388406
SKIP_INSTALL = YES;
389407
SWIFT_OBJC_INTERFACE_HEADER_NAME = "$(SWIFT_MODULE_NAME)-Swift.h";
390408
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
391-
SWIFT_SWIFT3_OBJC_INFERENCE = On;
392-
SWIFT_VERSION = 4.0;
409+
SWIFT_VERSION = 5.0;
393410
};
394411
name = Release;
395412
};
@@ -400,8 +417,7 @@
400417
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
401418
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.KeyboardHelperTests;
402419
PRODUCT_NAME = "$(TARGET_NAME)";
403-
SWIFT_SWIFT3_OBJC_INFERENCE = On;
404-
SWIFT_VERSION = 4.0;
420+
SWIFT_VERSION = 5.0;
405421
};
406422
name = Debug;
407423
};
@@ -413,8 +429,7 @@
413429
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.KeyboardHelperTests;
414430
PRODUCT_NAME = "$(TARGET_NAME)";
415431
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
416-
SWIFT_SWIFT3_OBJC_INFERENCE = On;
417-
SWIFT_VERSION = 4.0;
432+
SWIFT_VERSION = 5.0;
418433
};
419434
name = Release;
420435
};

KeyboardHelper.xcodeproj/xcshareddata/xcschemes/KeyboardHelper.xcscheme

Lines changed: 12 additions & 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 = "0810"
3+
LastUpgradeVersion = "1020"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,7 +26,18 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
codeCoverageEnabled = "YES"
30+
onlyGenerateCoverageForSpecifiedTargets = "YES"
2931
shouldUseLaunchSchemeArgsEnv = "YES">
32+
<CodeCoverageTargets>
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "275BCA761C57C9F800FF3647"
36+
BuildableName = "KeyboardHelper.framework"
37+
BlueprintName = "KeyboardHelper"
38+
ReferencedContainer = "container:KeyboardHelper.xcodeproj">
39+
</BuildableReference>
40+
</CodeCoverageTargets>
3041
<Testables>
3142
<TestableReference
3243
skipped = "NO">

KeyboardHelper/Classes/KeyboardAppearanceInfo.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ public struct KeyboardAppearanceInfo {
2222

2323
/// Getter for the UIKeyboard frame begin infokey. Returns a `CGRect` or `CGRectZero`.
2424
public var beginFrame: CGRect {
25-
return (userInfo[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue ?? .zero
25+
return (userInfo[UIResponder.keyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue ?? .zero
2626
}
2727

2828

2929
/// Getter for the UIKeyboard frame end infokey. Return a `CGRect` or `CGRectZero`.
3030
public var endFrame: CGRect {
31-
return (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue ?? .zero
31+
return (userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue ?? .zero
3232
}
3333

3434

@@ -37,29 +37,29 @@ public struct KeyboardAppearanceInfo {
3737
/// That variable will help to keep track of which app uses the keyboard at the moment.
3838
/// If it is the current app it is true, if not it is false.
3939
public var belongsToCurrentApp: Bool {
40-
return (userInfo[UIKeyboardIsLocalUserInfoKey] as? Bool) ?? true
40+
return (userInfo[UIResponder.keyboardIsLocalUserInfoKey] as? Bool) ?? true
4141

4242
}
4343

4444

4545
/// Getter for the duration of the keyboard appear/disappear animation.
4646
/// By default: `0.25`.
4747
public var animationDuration: Double {
48-
return (userInfo[UIKeyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue ?? 0.25
48+
return (userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue ?? 0.25
4949
}
5050

5151
/// Getter for the animation curve.
5252
/// By default: `EaseInOut`.
53-
public var animationCurve: UIViewAnimationCurve {
54-
guard let value = userInfo[UIKeyboardAnimationCurveUserInfoKey] as? Int else { return .easeInOut }
55-
return UIViewAnimationCurve(rawValue: value) ?? .easeInOut
53+
public var animationCurve: UIView.AnimationCurve {
54+
guard let value = userInfo[UIResponder.keyboardAnimationCurveUserInfoKey] as? Int else { return .easeInOut }
55+
return UIView.AnimationCurve(rawValue: value) ?? .easeInOut
5656
}
5757

5858

5959
/// Getter for the animation option.
6060
/// That variable will help to keep track of the keyboard appearence.
61-
public var animationOptions: UIViewAnimationOptions {
62-
return UIViewAnimationOptions(rawValue: UInt(animationCurve.rawValue << 16))
61+
public var animationOptions: UIView.AnimationOptions {
62+
return UIView.AnimationOptions(rawValue: UInt(animationCurve.rawValue << 16))
6363
}
6464

6565
/// Animate a `UView` while the keyboard appears and check if animation is finished.

KeyboardHelper/Classes/KeyboardHelper.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public class KeyboardHelper {
4545
required public init(delegate: KeyboardHelperDelegate) {
4646
self.delegate = delegate
4747

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)
48+
NotificationCenter.default.addObserver(self, selector: #selector(KeyboardHelper.keyboardWillAppear(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
49+
NotificationCenter.default.addObserver(self, selector: #selector(KeyboardHelper.keyboardWillDisappear(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)
5050
}
5151

5252

KeyboardHelperTests/Tests/KeyboardAppearanceInfoTests.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ class KeyboardAppearanceInfoTests: XCTestCase {
1919

2020
// Create test info
2121
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)),
24-
UIKeyboardAnimationDurationUserInfoKey: 3.0,
25-
UIKeyboardAnimationCurveUserInfoKey: NSNumber(integerLiteral: UIViewAnimationCurve.easeOut.rawValue),
22+
UIResponder.keyboardFrameBeginUserInfoKey: NSValue(cgRect: CGRect(x: 100, y: 100, width: 100, height: 100)),
23+
UIResponder.keyboardFrameEndUserInfoKey: NSValue(cgRect: CGRect(x: 200, y: 200, width: 200, height: 200)),
24+
UIResponder.keyboardAnimationDurationUserInfoKey: 3.0,
25+
UIResponder.keyboardAnimationCurveUserInfoKey: NSNumber(integerLiteral: UIView.AnimationCurve.easeOut.rawValue),
2626
]
2727

2828
if #available(iOS 9.0, *) {
29-
testUserInfo[UIKeyboardIsLocalUserInfoKey] = false
29+
testUserInfo[UIResponder.keyboardIsLocalUserInfoKey] = false
3030
} else {
3131
print("UIKeyboardIsLocalUserInfoKey is not available before iOS9.")
3232
}
3333

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

@@ -69,9 +69,9 @@ class KeyboardAppearanceInfoTests: XCTestCase {
6969
}
7070

7171
func testAnimationCurve() {
72-
XCTAssertEqual(appearanceInfo.animationCurve, UIViewAnimationCurve.easeOut,
72+
XCTAssertEqual(appearanceInfo.animationCurve, UIView.AnimationCurve.easeOut,
7373
"Parsing animationCurve from keyboard appearance info failed.")
74-
XCTAssertEqual(defaultsAppearanceInfo.animationCurve, UIViewAnimationCurve.easeInOut,
74+
XCTAssertEqual(defaultsAppearanceInfo.animationCurve, UIView.AnimationCurve.easeInOut,
7575
"Parsing default animationCurve from keyboard appearance info failed.")
7676
}
7777

KeyboardHelperTests/Tests/KeyboardHelperTests.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ class KeyboardHelperTests: XCTestCase {
5757
// NSNotificationCenter.defaultCenter().postNotificationName(UIKeyboardWillShowNotification, object: kh)
5858
let notification : Notification
5959
if #available(iOS 9.0, *) {
60-
notification = Notification(name: NSNotification.Name.UIKeyboardWillShow, object: kh, userInfo:[
61-
UIKeyboardAnimationCurveUserInfoKey : NSNumber(value: 7),
62-
UIKeyboardAnimationDurationUserInfoKey : NSNumber(value: 0.25),
63-
UIKeyboardFrameBeginUserInfoKey : NSValue(cgRect: CGRect(x: 0, y: 667, width: 375, height: 0)),
64-
UIKeyboardFrameEndUserInfoKey : NSValue(cgRect: CGRect(x: 0, y: 409, width: 375, height: 258)),
65-
UIKeyboardIsLocalUserInfoKey : NSNumber(value: true)
60+
notification = Notification(name: UIResponder.keyboardWillShowNotification, object: kh, userInfo:[
61+
UIResponder.keyboardAnimationCurveUserInfoKey : NSNumber(value: 7),
62+
UIResponder.keyboardAnimationDurationUserInfoKey : NSNumber(value: 0.25),
63+
UIResponder.keyboardFrameBeginUserInfoKey : NSValue(cgRect: CGRect(x: 0, y: 667, width: 375, height: 0)),
64+
UIResponder.keyboardFrameEndUserInfoKey : NSValue(cgRect: CGRect(x: 0, y: 409, width: 375, height: 258)),
65+
UIResponder.keyboardIsLocalUserInfoKey : NSNumber(value: true)
6666
])
6767
} else {
68-
notification = Notification(name: NSNotification.Name.UIKeyboardWillShow, object: nil, userInfo:[
69-
UIKeyboardAnimationCurveUserInfoKey : NSNumber(value: 7),
70-
UIKeyboardAnimationDurationUserInfoKey : NSNumber(value: 0.25),
71-
UIKeyboardFrameBeginUserInfoKey : NSValue(cgRect: CGRect(x: 0, y: 667, width: 375, height: 0)),
72-
UIKeyboardFrameEndUserInfoKey : NSValue(cgRect: CGRect(x: 0, y: 409, width: 375, height: 258))
68+
notification = Notification(name: UIResponder.keyboardWillShowNotification, object: nil, userInfo:[
69+
UIResponder.keyboardAnimationCurveUserInfoKey : NSNumber(value: 7),
70+
UIResponder.keyboardAnimationDurationUserInfoKey : NSNumber(value: 0.25),
71+
UIResponder.keyboardFrameBeginUserInfoKey : NSValue(cgRect: CGRect(x: 0, y: 667, width: 375, height: 0)),
72+
UIResponder.keyboardFrameEndUserInfoKey : NSValue(cgRect: CGRect(x: 0, y: 409, width: 375, height: 258))
7373
])
7474
}
7575

@@ -87,7 +87,7 @@ class KeyboardHelperTests: XCTestCase {
8787
return
8888
}
8989
XCTAssertNotNil(result)
90-
XCTAssertEqual(result.animationCurve, UIViewAnimationCurve(rawValue: 7))
90+
XCTAssertEqual(result.animationCurve, UIView.AnimationCurve(rawValue: 7))
9191
XCTAssertEqual(result.animationDuration, 0.25)
9292
XCTAssertEqual(result.beginFrame, CGRect(x: 0, y: 667, width: 375, height: 0))
9393
XCTAssertEqual(result.endFrame, CGRect(x: 0, y: 409, width: 375, height: 258))
@@ -107,7 +107,7 @@ class KeyboardHelperTests: XCTestCase {
107107
let expectation = self.expectation(description: "KeyboardHelper calls the delegate as the result of receiving the hide notification")
108108
spyDelegate.expectation = expectation
109109

110-
NotificationCenter.default.post(name: NSNotification.Name.UIKeyboardWillHide, object: kh)
110+
NotificationCenter.default.post(name: UIResponder.keyboardWillHideNotification, object: kh)
111111

112112

113113
waitForExpectations(timeout: 1) { error in

0 commit comments

Comments
 (0)