From 9b287503443be5b7217d7c798621246471559ff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20Mu=CC=88llner?= Date: Sun, 22 Nov 2020 03:45:36 +0100 Subject: [PATCH] Linter cleanup Check warning on line 16 in Package.swift @github-actions github-actions / lint Package.swift#L16 Trailing Comma Violation: Collection literals should not have trailing commas. (trailing_comma) Check warning on line 26 in Package.swift @github-actions github-actions / lint Package.swift#L26 Trailing Comma Violation: Collection literals should not have trailing commas. (trailing_comma) Check warning on line 6 in Tests/GameKitUITests/XCTestManifests.swift @github-actions github-actions / lint Tests/GameKitUITests/XCTestManifests.swift#L6 Trailing Comma Violation: Collection literals should not have trailing commas. (trailing_comma) Check warning on line 13 in Tests/GameKitUITests/GameKitUITests.swift @github-actions github-actions / lint Tests/GameKitUITests/GameKitUITests.swift#L13 Trailing Comma Violation: Collection literals should not have trailing commas. (trailing_comma) Check warning on line 35 in Sources/GameKitUI/GKAuthenticationView.swift @github-actions github-actions / lint Sources/GameKitUI/GKAuthenticationView.swift#L35 Line Length Violation: Line should be 120 characters or less: currently 141 characters (line_length) Check warning on line 46 in Sources/GameKitUI/GKAuthenticationView.swift @github-actions github-actions / lint Sources/GameKitUI/GKAuthenticationView.swift#L46 Line Length Violation: Line should be 120 characters or less: currently 161 characters (line_length) Check warning on line 82 in Sources/GameKitUI/GKAuthenticationView.swift @github-actions github-actions / lint Sources/GameKitUI/GKAuthenticationView.swift#L82 Notification Center Detachment Violation: An object should only remove itself as an observer in `deinit`. (notification_center_detachment) --- Package.swift | 4 +-- Sources/GameKitUI/GKAuthenticationView.swift | 29 +++++++++++--------- Tests/GameKitUITests/GameKitUITests.swift | 2 +- Tests/GameKitUITests/XCTestManifests.swift | 2 +- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/Package.swift b/Package.swift index c48c38e..bd97830 100644 --- a/Package.swift +++ b/Package.swift @@ -13,7 +13,7 @@ let package = Package( products: [ .library( name: "GameKitUI", - targets: ["GameKitUI"]), + targets: ["GameKitUI"]) ], dependencies: [ ], @@ -23,6 +23,6 @@ let package = Package( dependencies: []), .testTarget( name: "GameKitUITests", - dependencies: ["GameKitUI"]), + dependencies: ["GameKitUI"]) ] ) diff --git a/Sources/GameKitUI/GKAuthenticationView.swift b/Sources/GameKitUI/GKAuthenticationView.swift index 3a6f0d2..8d7e298 100644 --- a/Sources/GameKitUI/GKAuthenticationView.swift +++ b/Sources/GameKitUI/GKAuthenticationView.swift @@ -32,7 +32,8 @@ public struct GKAuthenticationView: UIViewControllerRepresentable { public let failed: ((Error) -> Void) public let authenticated: ((String) -> Void) - public func makeUIViewController(context: UIViewControllerRepresentableContext) -> GKAuthenticationViewController { + public func makeUIViewController( + context: UIViewControllerRepresentableContext) -> GKAuthenticationViewController { let authenticationViewController = GKAuthenticationViewController { (state) in self.state(state) } failed: { (error) in @@ -43,7 +44,9 @@ public struct GKAuthenticationView: UIViewControllerRepresentable { return authenticationViewController } - public func updateUIViewController(_ uiViewController: GKAuthenticationViewController, context: UIViewControllerRepresentableContext) { + public func updateUIViewController( + _ uiViewController: GKAuthenticationViewController, + context: UIViewControllerRepresentableContext) { } } @@ -60,28 +63,28 @@ public class GKAuthenticationViewController: UIViewController { self.failed = failed self.authenticated = authenticated super.init(nibName: nil, bundle: nil) - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - public override func viewWillAppear(_ animated: Bool) { - super.viewWillAppear(animated) + // Setup internal observer for GameKit authentication changes NotificationCenter.default.addObserver( self, selector: #selector(GKAuthenticationViewController.authenticationChanged), name: Notification.Name.GKPlayerAuthenticationDidChangeNotificationName, object: nil ) - self.authenticate() } - public override func viewWillDisappear(_ animated: Bool) { - super.viewWillDisappear(animated) + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + deinit { NotificationCenter.default.removeObserver(self) } + public override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + self.authenticate() + } + @objc fileprivate func authenticationChanged() { if GKLocalPlayer.local.isAuthenticated { self.stateChanged(.succeeded) diff --git a/Tests/GameKitUITests/GameKitUITests.swift b/Tests/GameKitUITests/GameKitUITests.swift index 52f5fd1..0774534 100644 --- a/Tests/GameKitUITests/GameKitUITests.swift +++ b/Tests/GameKitUITests/GameKitUITests.swift @@ -10,6 +10,6 @@ final class GameKitUITests: XCTestCase { } static var allTests = [ - ("testExample", testExample), + ("testExample", testExample) ] } diff --git a/Tests/GameKitUITests/XCTestManifests.swift b/Tests/GameKitUITests/XCTestManifests.swift index 19b50a1..c9256b8 100644 --- a/Tests/GameKitUITests/XCTestManifests.swift +++ b/Tests/GameKitUITests/XCTestManifests.swift @@ -3,7 +3,7 @@ import XCTest #if !canImport(ObjectiveC) public func allTests() -> [XCTestCaseEntry] { return [ - testCase(GameKitUITests.allTests), + testCase(GameKitUITests.allTests) ] } #endif