From 4255cf4f6666fa6e8e27cbe432228292f10afc38 Mon Sep 17 00:00:00 2001 From: Britney Smith Date: Mon, 12 Nov 2018 13:45:53 -0500 Subject: [PATCH 01/25] Added import command for UIKit; resolved 6 build errors --- Source/DialogManager.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/DialogManager.swift b/Source/DialogManager.swift index ea68953..1fe1a6b 100755 --- a/Source/DialogManager.swift +++ b/Source/DialogManager.swift @@ -7,6 +7,7 @@ // import Foundation +import UIKit protocol Dialogable { var message: String { get } From 1248e2e378f298403dba90179a6f7a7765f4482d Mon Sep 17 00:00:00 2001 From: Britney Smith Date: Mon, 12 Nov 2018 16:23:58 -0500 Subject: [PATCH 02/25] Added line to disable SwiftLint rule that did not allow valid characters used in DialogType enum associated values --- .../Example/Assets.xcassets/AppIcon.appiconset/Contents.json | 5 +++++ Source/DialogManager.swift | 2 ++ 2 files changed, 7 insertions(+) diff --git a/Example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json b/Example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json index b8236c6..19882d5 100755 --- a/Example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/Example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -39,6 +39,11 @@ "idiom" : "iphone", "size" : "60x60", "scale" : "3x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" } ], "info" : { diff --git a/Source/DialogManager.swift b/Source/DialogManager.swift index 1fe1a6b..63f7df8 100755 --- a/Source/DialogManager.swift +++ b/Source/DialogManager.swift @@ -6,6 +6,8 @@ // // +// swiftlint:disable identifier_name + import Foundation import UIKit From 2b1a386e6aef408a1c1d7cee7dd8eb7861fd53c5 Mon Sep 17 00:00:00 2001 From: Britney Smith Date: Mon, 12 Nov 2018 17:03:27 -0500 Subject: [PATCH 03/25] Updated build settings to use Swift 4.2 in root, removed unnecessary line from Podfile --- LaunchGate.xcodeproj/project.pbxproj | 6 ++---- Podfile | 2 -- Podfile.lock | 14 +++++++------- Source/DialogManager.swift | 2 -- Source/LaunchGate.swift | 2 +- 5 files changed, 10 insertions(+), 16 deletions(-) diff --git a/LaunchGate.xcodeproj/project.pbxproj b/LaunchGate.xcodeproj/project.pbxproj index cb94d3e..8000acd 100755 --- a/LaunchGate.xcodeproj/project.pbxproj +++ b/LaunchGate.xcodeproj/project.pbxproj @@ -504,6 +504,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -555,6 +556,7 @@ MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -579,7 +581,6 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -599,7 +600,6 @@ PRODUCT_BUNDLE_IDENTIFIER = com.dtrenz.LaunchGate; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 4.0; }; name = Release; }; @@ -611,7 +611,6 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.dtrenz.LaunchGateTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -623,7 +622,6 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.dtrenz.LaunchGateTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; }; name = Release; }; diff --git a/Podfile b/Podfile index d72d3d1..6ac182d 100755 --- a/Podfile +++ b/Podfile @@ -1,8 +1,6 @@ source 'https://github.com/CocoaPods/Specs.git' use_frameworks! -pod 'SwiftLint' - target 'LaunchGateTests' do platform :ios, '8.3' inherit! :search_paths diff --git a/Podfile.lock b/Podfile.lock index 7323484..566362e 100755 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,7 +1,7 @@ PODS: - - Nimble (7.1.3) - - Quick (1.3.1) - - SwiftLint (0.26.0) + - Nimble (7.3.1) + - Quick (1.3.2) + - SwiftLint (0.27.0) DEPENDENCIES: - Nimble @@ -15,10 +15,10 @@ SPEC REPOS: - SwiftLint SPEC CHECKSUMS: - Nimble: 2839b01d1b31f6a6a7777a221f0d91cf52e8e27b - Quick: d17304d58d0d169dd0bd1c6e5c28e3318de32a1a - SwiftLint: f6b83e8d95ee1e91e11932d843af4fdcbf3fc764 + Nimble: 04f732da099ea4d153122aec8c2a88fd0c7219ae + Quick: 2623cb30d7a7f41ca62f684f679586558f483d46 + SwiftLint: 3207c1faa2240bf8973b191820a116113cd11073 -PODFILE CHECKSUM: 80b19f99959846e7855de4619381077e49a4e498 +PODFILE CHECKSUM: c66a903b4dd3d64e68e8dcb4170d38ac84ba0147 COCOAPODS: 1.5.3 diff --git a/Source/DialogManager.swift b/Source/DialogManager.swift index 63f7df8..1fe1a6b 100755 --- a/Source/DialogManager.swift +++ b/Source/DialogManager.swift @@ -6,8 +6,6 @@ // // -// swiftlint:disable identifier_name - import Foundation import UIKit diff --git a/Source/LaunchGate.swift b/Source/LaunchGate.swift index e2337a6..6b76076 100755 --- a/Source/LaunchGate.swift +++ b/Source/LaunchGate.swift @@ -50,7 +50,7 @@ public class LaunchGate { /// Check the configuration file and perform any appropriate action. public func check() { - performCheck(RemoteFileManager(remoteFileURL: (configurationFileURL as URL))) + performCheck(RemoteFileManager(remoteFileURL: (configurationFileURL))) } // MARK: - Internal API From b5fc3066309c456c7f32c22cf605658d97593042 Mon Sep 17 00:00:00 2001 From: Britney Smith Date: Mon, 12 Nov 2018 17:12:07 -0500 Subject: [PATCH 04/25] Conformed models to Codable, changed vars to lets --- Source/AlertConfiguration.swift | 6 +++--- Source/LaunchGateConfiguration.swift | 2 +- Source/UpdateConfiguration.swift | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/AlertConfiguration.swift b/Source/AlertConfiguration.swift index 6528f1a..81717b4 100755 --- a/Source/AlertConfiguration.swift +++ b/Source/AlertConfiguration.swift @@ -7,10 +7,10 @@ import Foundation -public struct AlertConfiguration: Dialogable, Rememberable { +public struct AlertConfiguration: Decodable, Dialogable, Rememberable { - var message = "" - var blocking = false + let message: String + let blocking: Bool init?(message: String, blocking: Bool) { guard !message.isEmpty else { return nil } diff --git a/Source/LaunchGateConfiguration.swift b/Source/LaunchGateConfiguration.swift index 19aa168..4904623 100755 --- a/Source/LaunchGateConfiguration.swift +++ b/Source/LaunchGateConfiguration.swift @@ -9,7 +9,7 @@ import Foundation /// The configuration object that should be created as the result of parsing the remote configuration file. -public struct LaunchGateConfiguration { +public struct LaunchGateConfiguration: Decodable { /// An `AlertConfiguration`, parsed from the configuration file. var alert: AlertConfiguration? diff --git a/Source/UpdateConfiguration.swift b/Source/UpdateConfiguration.swift index de4088a..0b8fd00 100755 --- a/Source/UpdateConfiguration.swift +++ b/Source/UpdateConfiguration.swift @@ -8,10 +8,10 @@ import Foundation -public struct UpdateConfiguration: Dialogable, Rememberable { +public struct UpdateConfiguration: Decodable, Dialogable, Rememberable { - var version = "" - var message = "" + let version: String + let message: String init?(version: String, message: String) { guard !version.isEmpty else { return nil } From 53ebcf116f8a74ad0b3f27980666f0710e957b64 Mon Sep 17 00:00:00 2001 From: Britney Smith Date: Tue, 13 Nov 2018 10:01:38 -0500 Subject: [PATCH 05/25] Starting replacing parsing methods using JSOnDecoder --- Source/DefaultParser.swift | 85 +++++++++++++++++++------------- Source/UpdateConfiguration.swift | 2 +- 2 files changed, 51 insertions(+), 36 deletions(-) diff --git a/Source/DefaultParser.swift b/Source/DefaultParser.swift index 610071b..4943748 100755 --- a/Source/DefaultParser.swift +++ b/Source/DefaultParser.swift @@ -9,7 +9,11 @@ import Foundation class DefaultParser: LaunchGateParser { - +// func parse(_ jsonData: Data) -> LaunchGateConfiguration? { +// <#code#> +// } + + typealias JSON = [String: AnyObject] enum Error: LaunchGateError { @@ -31,42 +35,53 @@ class DefaultParser: LaunchGateParser { } } } - - func parse(_ jsonData: Data) -> LaunchGateConfiguration? { - do { - let jsonData = try JSONSerialization.jsonObject(with: jsonData, options: []) - guard let json = jsonData as? JSON else { throw Error.unableToParseConfigurationObject } - guard let config = json["ios"] else { throw Error.unableToParseConfigurationObject } - - var alert: AlertConfiguration? - var optionalUpdate: UpdateConfiguration? - var requiredUpdate: UpdateConfiguration? - - if let alertJSON = config["alert"] as? JSON { - alert = try DefaultParser.parseAlert(alertJSON) - } - - if let optionalUpdateJSON = config["optionalUpdate"] as? JSON { - optionalUpdate = try DefaultParser.parseOptionalUpdate(optionalUpdateJSON) - } - - if let requiredUpdateJSON = config["requiredUpdate"] as? JSON { - requiredUpdate = try DefaultParser.parseRequiredUpdate(requiredUpdateJSON) - } - - return LaunchGateConfiguration(alert: alert, optionalUpdate: optionalUpdate, requiredUpdate: requiredUpdate) - } catch let error as DefaultParser.Error { - print("LaunchGate — Error: \(error)") - } catch let error as NSError { - print("LaunchGate — Error: \(error.localizedDescription)") - - if let recoverySuggestion = error.localizedRecoverySuggestion { - print(recoverySuggestion) - } + func parse(_ jsonData: Data) -> AlertConfiguration? { + do { + let decoder = JSONDecoder() + let result = try decoder.decode(AlertConfiguration.self, from: jsonData) + return result + } catch { + print(error) + return nil + } + return nil } - return nil - } +// func parse(_ jsonData: Data) -> LaunchGateConfiguration? { +// do { +// let jsonData = try JSONSerialization.jsonObject(with: jsonData, options: []) +// guard let json = jsonData as? JSON else { throw Error.unableToParseConfigurationObject } +// guard let config = json["ios"] else { throw Error.unableToParseConfigurationObject } +// +// var alert: AlertConfiguration? +// var optionalUpdate: UpdateConfiguration? +// var requiredUpdate: UpdateConfiguration? +// +// if let alertJSON = config["alert"] as? JSON { +// alert = try DefaultParser.parseAlert(alertJSON) +// } +// +// if let optionalUpdateJSON = config["optionalUpdate"] as? JSON { +// optionalUpdate = try DefaultParser.parseOptionalUpdate(optionalUpdateJSON) +// } +// +// if let requiredUpdateJSON = config["requiredUpdate"] as? JSON { +// requiredUpdate = try DefaultParser.parseRequiredUpdate(requiredUpdateJSON) +// } +// +// return LaunchGateConfiguration(alert: alert, optionalUpdate: optionalUpdate, requiredUpdate: requiredUpdate) +// } catch let error as DefaultParser.Error { +// print("LaunchGate — Error: \(error)") +// } catch let error as NSError { +// print("LaunchGate — Error: \(error.localizedDescription)") +// +// if let recoverySuggestion = error.localizedRecoverySuggestion { +// print(recoverySuggestion) +// } +// } +// +// return nil +// } private static func parseAlert(_ json: JSON) throws -> AlertConfiguration? { guard let message = json["message"] as? String else { throw Error.unableToParseAlert } diff --git a/Source/UpdateConfiguration.swift b/Source/UpdateConfiguration.swift index 0b8fd00..ec1113b 100755 --- a/Source/UpdateConfiguration.swift +++ b/Source/UpdateConfiguration.swift @@ -9,7 +9,7 @@ import Foundation public struct UpdateConfiguration: Decodable, Dialogable, Rememberable { - + /// NOTE: 'version' name not the same; 'minimumVersion' let version: String let message: String From f9d1b7393ef7a7de486e9a7148c57cd9c7b6adbc Mon Sep 17 00:00:00 2001 From: Britney Smith Date: Tue, 13 Nov 2018 10:09:11 -0500 Subject: [PATCH 06/25] Rewrote more parsing methods --- Source/DefaultParser.swift | 134 +++++++++++++++++++++---------------- 1 file changed, 75 insertions(+), 59 deletions(-) diff --git a/Source/DefaultParser.swift b/Source/DefaultParser.swift index 4943748..55f11c9 100755 --- a/Source/DefaultParser.swift +++ b/Source/DefaultParser.swift @@ -9,11 +9,7 @@ import Foundation class DefaultParser: LaunchGateParser { -// func parse(_ jsonData: Data) -> LaunchGateConfiguration? { -// <#code#> -// } - typealias JSON = [String: AnyObject] enum Error: LaunchGateError { @@ -35,7 +31,45 @@ class DefaultParser: LaunchGateParser { } } } - func parse(_ jsonData: Data) -> AlertConfiguration? { + + + func parse(_ jsonData: Data) -> LaunchGateConfiguration? { + do { + let jsonData = try JSONSerialization.jsonObject(with: jsonData, options: []) + guard let json = jsonData as? JSON else { throw Error.unableToParseConfigurationObject } + guard let config = json["ios"] else { throw Error.unableToParseConfigurationObject } + + var alert: AlertConfiguration? + var optionalUpdate: UpdateConfiguration? + var requiredUpdate: UpdateConfiguration? + + if let alertJSON = config["alert"] as? JSON { + alert = try DefaultParser.parseAlert(alertJSON) + } + + if let optionalUpdateJSON = config["optionalUpdate"] as? JSON { + optionalUpdate = try DefaultParser.parseOptionalUpdate(optionalUpdateJSON) + } + + if let requiredUpdateJSON = config["requiredUpdate"] as? JSON { + requiredUpdate = try DefaultParser.parseRequiredUpdate(requiredUpdateJSON) + } + + return LaunchGateConfiguration(alert: alert, optionalUpdate: optionalUpdate, requiredUpdate: requiredUpdate) + } catch let error as DefaultParser.Error { + print("LaunchGate — Error: \(error)") + } catch let error as NSError { + print("LaunchGate — Error: \(error.localizedDescription)") + + if let recoverySuggestion = error.localizedRecoverySuggestion { + print(recoverySuggestion) + } + } + + return nil + } + + private static func parseAlert(_ jsonData: Data) -> AlertConfiguration? { do { let decoder = JSONDecoder() let result = try decoder.decode(AlertConfiguration.self, from: jsonData) @@ -44,64 +78,46 @@ class DefaultParser: LaunchGateParser { print(error) return nil } - return nil } - -// func parse(_ jsonData: Data) -> LaunchGateConfiguration? { -// do { -// let jsonData = try JSONSerialization.jsonObject(with: jsonData, options: []) -// guard let json = jsonData as? JSON else { throw Error.unableToParseConfigurationObject } -// guard let config = json["ios"] else { throw Error.unableToParseConfigurationObject } -// -// var alert: AlertConfiguration? -// var optionalUpdate: UpdateConfiguration? -// var requiredUpdate: UpdateConfiguration? -// -// if let alertJSON = config["alert"] as? JSON { -// alert = try DefaultParser.parseAlert(alertJSON) -// } -// -// if let optionalUpdateJSON = config["optionalUpdate"] as? JSON { -// optionalUpdate = try DefaultParser.parseOptionalUpdate(optionalUpdateJSON) -// } -// -// if let requiredUpdateJSON = config["requiredUpdate"] as? JSON { -// requiredUpdate = try DefaultParser.parseRequiredUpdate(requiredUpdateJSON) -// } -// -// return LaunchGateConfiguration(alert: alert, optionalUpdate: optionalUpdate, requiredUpdate: requiredUpdate) -// } catch let error as DefaultParser.Error { -// print("LaunchGate — Error: \(error)") -// } catch let error as NSError { -// print("LaunchGate — Error: \(error.localizedDescription)") -// -// if let recoverySuggestion = error.localizedRecoverySuggestion { -// print(recoverySuggestion) -// } -// } + private static func parseOptionalUpdate(_ jsonData: Data) -> UpdateConfiguration? { + do { + let decoder = JSONDecoder() + let result = try decoder.decode(UpdateConfiguration.self, from: jsonData) + return result + } catch { + print(error) + return nil + } + } + private static func parseRequiredUpdate(_ jsonData: Data) -> UpdateConfiguration? { + do { + let decoder = JSONDecoder() + let result = try decoder.decode(UpdateConfiguration.self, from: jsonData) + return result + } catch { + print(error) + return nil + } + } +// private static func parseAlert(_ json: JSON) throws -> AlertConfiguration? { +// guard let message = json["message"] as? String else { throw Error.unableToParseAlert } +// guard let blocking = json["blocking"] as? Bool else { throw Error.unableToParseAlert } // -// return nil +// return AlertConfiguration(message: message, blocking: blocking) // } - private static func parseAlert(_ json: JSON) throws -> AlertConfiguration? { - guard let message = json["message"] as? String else { throw Error.unableToParseAlert } - guard let blocking = json["blocking"] as? Bool else { throw Error.unableToParseAlert } - - return AlertConfiguration(message: message, blocking: blocking) - } - - private static func parseOptionalUpdate(_ json: JSON) throws -> UpdateConfiguration? { - guard let version = json["optionalVersion"] as? String else { throw Error.unableToParseOptionalUpdate } - guard let message = json["message"] as? String else { throw Error.unableToParseOptionalUpdate } - - return UpdateConfiguration(version: version, message: message) - } - - private static func parseRequiredUpdate(_ json: JSON) throws -> UpdateConfiguration? { - guard let version = json["minimumVersion"] as? String else { throw Error.unableToParseRequiredUpdate } - guard let message = json["message"] as? String else { throw Error.unableToParseRequiredUpdate } +// private static func parseOptionalUpdate(_ json: JSON) throws -> UpdateConfiguration? { +// guard let version = json["optionalVersion"] as? String else { throw Error.unableToParseOptionalUpdate } +// guard let message = json["message"] as? String else { throw Error.unableToParseOptionalUpdate } +// +// return UpdateConfiguration(version: version, message: message) +// } - return UpdateConfiguration(version: version, message: message) - } +// private static func parseRequiredUpdate(_ json: JSON) throws -> UpdateConfiguration? { +// guard let version = json["minimumVersion"] as? String else { throw Error.unableToParseRequiredUpdate } +// guard let message = json["message"] as? String else { throw Error.unableToParseRequiredUpdate } +// +// return UpdateConfiguration(version: version, message: message) +// } } From 91697fc3286e246050911d0c735c660ab7b0ef5d Mon Sep 17 00:00:00 2001 From: Britney Smith Date: Tue, 13 Nov 2018 13:13:36 -0500 Subject: [PATCH 07/25] Wrote decoder initializer --- Source/DefaultParser.swift | 8 ++++---- Source/UpdateConfiguration.swift | 23 +++++++++++++++++++++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Source/DefaultParser.swift b/Source/DefaultParser.swift index 55f11c9..1317429 100755 --- a/Source/DefaultParser.swift +++ b/Source/DefaultParser.swift @@ -79,20 +79,20 @@ class DefaultParser: LaunchGateParser { return nil } } - private static func parseOptionalUpdate(_ jsonData: Data) -> UpdateConfiguration? { + private static func parseOptionalUpdate(_ jsonData: Data) -> OptionalUpdate? { do { let decoder = JSONDecoder() - let result = try decoder.decode(UpdateConfiguration.self, from: jsonData) + let result = try decoder.decode(OptionalUpdate.self, from: jsonData) return result } catch { print(error) return nil } } - private static func parseRequiredUpdate(_ jsonData: Data) -> UpdateConfiguration? { + private static func parseRequiredUpdate(_ jsonData: Data) -> RequiredUpdate? { do { let decoder = JSONDecoder() - let result = try decoder.decode(UpdateConfiguration.self, from: jsonData) + let result = try decoder.decode(RequiredUpdate.self, from: jsonData) return result } catch { print(error) diff --git a/Source/UpdateConfiguration.swift b/Source/UpdateConfiguration.swift index ec1113b..70d79ae 100755 --- a/Source/UpdateConfiguration.swift +++ b/Source/UpdateConfiguration.swift @@ -10,8 +10,8 @@ import Foundation public struct UpdateConfiguration: Decodable, Dialogable, Rememberable { /// NOTE: 'version' name not the same; 'minimumVersion' - let version: String - let message: String + var version: String + var message: String init?(version: String, message: String) { guard !version.isEmpty else { return nil } @@ -20,6 +20,25 @@ public struct UpdateConfiguration: Decodable, Dialogable, Rememberable { self.version = version self.message = message } + public init(from decoder: Decoder) throws { + let optionalKeyedContainer = try decoder.container(keyedBy: OptionalCodingKeys.self) + let requiredKeyedContainer = try decoder.container(keyedBy: RequiredCodingKeys.self) + do { + version = try optionalKeyedContainer.decode(String.self, forKey: .version) + message = try optionalKeyedContainer.decode(String.self, forKey: .message) + } catch { + version = try requiredKeyedContainer.decode(String.self, forKey: .version) + message = try requiredKeyedContainer.decode(String.self, forKey: .message) + } + } + enum OptionalCodingKeys: String, CodingKey { + case version = "optionalVersion" + case message + } + enum RequiredCodingKeys: String, CodingKey { + case version = "minimumVersion" + case message + } // MARK: Rememberable Protocol Methods From 828aeb059aeab8742c97a53359f906e8157715d2 Mon Sep 17 00:00:00 2001 From: Britney Smith Date: Tue, 13 Nov 2018 15:39:47 -0500 Subject: [PATCH 08/25] WIP: Parser method --- .../xcschemes/LaunchGate.xcscheme | 17 +-- Source/DefaultParser.swift | 142 ++++++++++-------- Source/UpdateConfiguration.swift | 1 - 3 files changed, 80 insertions(+), 80 deletions(-) diff --git a/LaunchGate.xcodeproj/xcshareddata/xcschemes/LaunchGate.xcscheme b/LaunchGate.xcodeproj/xcshareddata/xcschemes/LaunchGate.xcscheme index 8693ead..d2e7eb8 100755 --- a/LaunchGate.xcodeproj/xcshareddata/xcschemes/LaunchGate.xcscheme +++ b/LaunchGate.xcodeproj/xcshareddata/xcschemes/LaunchGate.xcscheme @@ -43,10 +43,10 @@ + BlueprintIdentifier = "C5A878881C6A7A95004599C2" + BuildableName = "Example.app" + BlueprintName = "Example" + ReferencedContainer = "container:Example/Example.xcodeproj"> @@ -62,15 +62,6 @@ debugDocumentVersioning = "YES" debugServiceExtension = "internal" allowLocationSimulation = "YES"> - - - - diff --git a/Source/DefaultParser.swift b/Source/DefaultParser.swift index 1317429..efc6247 100755 --- a/Source/DefaultParser.swift +++ b/Source/DefaultParser.swift @@ -9,7 +9,6 @@ import Foundation class DefaultParser: LaunchGateParser { - typealias JSON = [String: AnyObject] enum Error: LaunchGateError { @@ -31,88 +30,99 @@ class DefaultParser: LaunchGateParser { } } } - - - func parse(_ jsonData: Data) -> LaunchGateConfiguration? { - do { - let jsonData = try JSONSerialization.jsonObject(with: jsonData, options: []) - guard let json = jsonData as? JSON else { throw Error.unableToParseConfigurationObject } - guard let config = json["ios"] else { throw Error.unableToParseConfigurationObject } - - var alert: AlertConfiguration? - var optionalUpdate: UpdateConfiguration? - var requiredUpdate: UpdateConfiguration? - - if let alertJSON = config["alert"] as? JSON { - alert = try DefaultParser.parseAlert(alertJSON) - } - - if let optionalUpdateJSON = config["optionalUpdate"] as? JSON { - optionalUpdate = try DefaultParser.parseOptionalUpdate(optionalUpdateJSON) - } - - if let requiredUpdateJSON = config["requiredUpdate"] as? JSON { - requiredUpdate = try DefaultParser.parseRequiredUpdate(requiredUpdateJSON) - } - - return LaunchGateConfiguration(alert: alert, optionalUpdate: optionalUpdate, requiredUpdate: requiredUpdate) - } catch let error as DefaultParser.Error { - print("LaunchGate — Error: \(error)") - } catch let error as NSError { - print("LaunchGate — Error: \(error.localizedDescription)") - - if let recoverySuggestion = error.localizedRecoverySuggestion { - print(recoverySuggestion) - } - } - - return nil - } - - private static func parseAlert(_ jsonData: Data) -> AlertConfiguration? { - do { - let decoder = JSONDecoder() - let result = try decoder.decode(AlertConfiguration.self, from: jsonData) - return result - } catch { - print(error) - return nil - } - } - private static func parseOptionalUpdate(_ jsonData: Data) -> OptionalUpdate? { + func parse(_ jsonData: Data) -> LaunchGateConfiguration? { do { let decoder = JSONDecoder() - let result = try decoder.decode(OptionalUpdate.self, from: jsonData) + let result = try decoder.decode(LaunchGateConfiguration.self, from: jsonData) return result - } catch { - print(error) - return nil - } - } - private static func parseRequiredUpdate(_ jsonData: Data) -> RequiredUpdate? { - do { - let decoder = JSONDecoder() - let result = try decoder.decode(RequiredUpdate.self, from: jsonData) - return result - } catch { - print(error) - return nil + } catch let error as NSError { + print("LaunchGate — Error: \(error.localizedDescription)") + if let recoverySuggestion = error.localizedRecoverySuggestion { + print(recoverySuggestion) + } } + return nil } +// func parse(_ jsonData: Data) -> LaunchGateConfiguration? { +// do { +// let jsonData = try JSONSerialization.jsonObject(with: jsonData, options: []) +// guard let json = jsonData as? JSON else { throw Error.unableToParseConfigurationObject } +// guard let config = json["ios"] else { throw Error.unableToParseConfigurationObject } +// +// var alert: AlertConfiguration? +// var optionalUpdate: UpdateConfiguration? +// var requiredUpdate: UpdateConfiguration? +// +// if let alertJSON = config["alert"] /*as? JSON*/ { +// alert = try DefaultParser.parseAlert(alertJSON) +// } +// +// if let optionalUpdateJSON = config["optionalUpdate"] as? JSON { +// optionalUpdate = try DefaultParser.parseOptionalUpdate(optionalUpdateJSON) +// } +// +// if let requiredUpdateJSON = config["requiredUpdate"] as? JSON { +// requiredUpdate = try DefaultParser.parseRequiredUpdate(requiredUpdateJSON) +// } +// +// return LaunchGateConfiguration(alert: alert, optionalUpdate: optionalUpdate, requiredUpdate: requiredUpdate) +// } catch let error as DefaultParser.Error { +// print("LaunchGate — Error: \(error)") +// } catch let error as NSError { +// print("LaunchGate — Error: \(error.localizedDescription)") +// +// if let recoverySuggestion = error.localizedRecoverySuggestion { +// print(recoverySuggestion) +// } +// } +// +// return nil +// } +// +// private static func parseAlert(_ jsonData: Data) -> AlertConfiguration? { +// do { +// let decoder = JSONDecoder() +// let result = try decoder.decode(AlertConfiguration.self, from: jsonData) +// return result +// } catch { +// print(error) +// return nil +// } +// } +// private static func parseOptionalUpdate(_ jsonData: Data) -> UpdateConfiguration? { +// do { +// let decoder = JSONDecoder() +// let result = try decoder.decode(UpdateConfiguration.self, from: jsonData) +// return result +// } catch { +// print(error) +// return nil +// } +// } +// private static func parseRequiredUpdate(_ jsonData: Data) -> UpdateConfiguration? { +// do { +// let decoder = JSONDecoder() +// let result = try decoder.decode(UpdateConfiguration.self, from: jsonData) +// return result +// } catch { +// print(error) +// return nil +// } +// } // private static func parseAlert(_ json: JSON) throws -> AlertConfiguration? { // guard let message = json["message"] as? String else { throw Error.unableToParseAlert } // guard let blocking = json["blocking"] as? Bool else { throw Error.unableToParseAlert } // // return AlertConfiguration(message: message, blocking: blocking) // } - +// // private static func parseOptionalUpdate(_ json: JSON) throws -> UpdateConfiguration? { // guard let version = json["optionalVersion"] as? String else { throw Error.unableToParseOptionalUpdate } // guard let message = json["message"] as? String else { throw Error.unableToParseOptionalUpdate } // // return UpdateConfiguration(version: version, message: message) // } - +// // private static func parseRequiredUpdate(_ json: JSON) throws -> UpdateConfiguration? { // guard let version = json["minimumVersion"] as? String else { throw Error.unableToParseRequiredUpdate } // guard let message = json["message"] as? String else { throw Error.unableToParseRequiredUpdate } diff --git a/Source/UpdateConfiguration.swift b/Source/UpdateConfiguration.swift index 70d79ae..9007bf5 100755 --- a/Source/UpdateConfiguration.swift +++ b/Source/UpdateConfiguration.swift @@ -9,7 +9,6 @@ import Foundation public struct UpdateConfiguration: Decodable, Dialogable, Rememberable { - /// NOTE: 'version' name not the same; 'minimumVersion' var version: String var message: String From 46ed62fd9d920abb4cab5acd57733aa480ef5f87 Mon Sep 17 00:00:00 2001 From: Britney Smith Date: Tue, 13 Nov 2018 17:29:22 -0500 Subject: [PATCH 09/25] WIP - Decoding LaunchGateConfiguration --- Source/DefaultParser.swift | 5 +---- Source/LaunchGateConfiguration.swift | 15 +++++++++++++++ Source/UpdateConfiguration.swift | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Source/DefaultParser.swift b/Source/DefaultParser.swift index efc6247..3e041ea 100755 --- a/Source/DefaultParser.swift +++ b/Source/DefaultParser.swift @@ -35,11 +35,8 @@ class DefaultParser: LaunchGateParser { let decoder = JSONDecoder() let result = try decoder.decode(LaunchGateConfiguration.self, from: jsonData) return result - } catch let error as NSError { + } catch let error { print("LaunchGate — Error: \(error.localizedDescription)") - if let recoverySuggestion = error.localizedRecoverySuggestion { - print(recoverySuggestion) - } } return nil } diff --git a/Source/LaunchGateConfiguration.swift b/Source/LaunchGateConfiguration.swift index 4904623..ad970b2 100755 --- a/Source/LaunchGateConfiguration.swift +++ b/Source/LaunchGateConfiguration.swift @@ -20,4 +20,19 @@ public struct LaunchGateConfiguration: Decodable { /// A required `UpdateConfiguration`, parsed from the configuration file. var requiredUpdate: UpdateConfiguration? + public init(from decoder:Decoder) throws { + let iosContainer = try decoder.container(keyedBy: IOSRootKey.self) + let alert = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .alert) + } + enum IOSRootKey: CodingKey { + case ios + case alert + case optionalUpdate + case requiredUpdate + } + enum ConfigCodingKeys: String, CodingKey { + case alert + case optionalUpdate + case requiredUpdate + } } diff --git a/Source/UpdateConfiguration.swift b/Source/UpdateConfiguration.swift index 9007bf5..375e9a3 100755 --- a/Source/UpdateConfiguration.swift +++ b/Source/UpdateConfiguration.swift @@ -21,11 +21,11 @@ public struct UpdateConfiguration: Decodable, Dialogable, Rememberable { } public init(from decoder: Decoder) throws { let optionalKeyedContainer = try decoder.container(keyedBy: OptionalCodingKeys.self) - let requiredKeyedContainer = try decoder.container(keyedBy: RequiredCodingKeys.self) do { version = try optionalKeyedContainer.decode(String.self, forKey: .version) message = try optionalKeyedContainer.decode(String.self, forKey: .message) } catch { + let requiredKeyedContainer = try decoder.container(keyedBy: RequiredCodingKeys.self) version = try requiredKeyedContainer.decode(String.self, forKey: .version) message = try requiredKeyedContainer.decode(String.self, forKey: .message) } From 8859add99556326380f068f6bed2157420d66a05 Mon Sep 17 00:00:00 2001 From: Britney Smith Date: Wed, 14 Nov 2018 09:30:34 -0500 Subject: [PATCH 10/25] WIP - changed container for root JSON object --- Source/LaunchGateConfiguration.swift | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/Source/LaunchGateConfiguration.swift b/Source/LaunchGateConfiguration.swift index ad970b2..f4c1f20 100755 --- a/Source/LaunchGateConfiguration.swift +++ b/Source/LaunchGateConfiguration.swift @@ -20,19 +20,22 @@ public struct LaunchGateConfiguration: Decodable { /// A required `UpdateConfiguration`, parsed from the configuration file. var requiredUpdate: UpdateConfiguration? - public init(from decoder:Decoder) throws { + public init(from decoder: Decoder) throws { let iosContainer = try decoder.container(keyedBy: IOSRootKey.self) - let alert = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .alert) + let ios = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .ios) + //let alert = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .alert) + //let optionalUpdate = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .optionalUpdate) + //let requiredUpdate = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .requiredUpdate) } enum IOSRootKey: CodingKey { case ios - case alert - case optionalUpdate - case requiredUpdate - } - enum ConfigCodingKeys: String, CodingKey { - case alert - case optionalUpdate - case requiredUpdate + //case alert + //case optionalUpdate + //case requiredUpdate } +// enum ConfigCodingKeys: String, CodingKey { +// case alert +// case optionalUpdate +// case requiredUpdate +// } } From 5c72248d0267147a1734e86b2bfe15ff3e1f19c0 Mon Sep 17 00:00:00 2001 From: Britney Smith Date: Wed, 14 Nov 2018 09:54:57 -0500 Subject: [PATCH 11/25] WIP - decoding rook object in nested container --- Source/LaunchGateConfiguration.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Source/LaunchGateConfiguration.swift b/Source/LaunchGateConfiguration.swift index f4c1f20..b4feb18 100755 --- a/Source/LaunchGateConfiguration.swift +++ b/Source/LaunchGateConfiguration.swift @@ -23,15 +23,19 @@ public struct LaunchGateConfiguration: Decodable { public init(from decoder: Decoder) throws { let iosContainer = try decoder.container(keyedBy: IOSRootKey.self) let ios = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .ios) + + let alert = try ios.decode(AlertConfiguration.self, forKey: .alert) + let optionalUpdate = try ios.decode(UpdateConfiguration.self, forKey: .optionalUpdate) + let requiredUpdate = try ios.decode(UpdateConfiguration.self, forKey: .requiredUpdate) //let alert = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .alert) //let optionalUpdate = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .optionalUpdate) //let requiredUpdate = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .requiredUpdate) } enum IOSRootKey: CodingKey { case ios - //case alert - //case optionalUpdate - //case requiredUpdate + case alert + case optionalUpdate + case requiredUpdate } // enum ConfigCodingKeys: String, CodingKey { // case alert From b1a18cd433f17714d4e860a6ddfd609cd4843f35 Mon Sep 17 00:00:00 2001 From: Britney Smith Date: Wed, 14 Nov 2018 10:48:28 -0500 Subject: [PATCH 12/25] WIP - changed comment --- Source/DefaultParser.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/DefaultParser.swift b/Source/DefaultParser.swift index 3e041ea..728cee0 100755 --- a/Source/DefaultParser.swift +++ b/Source/DefaultParser.swift @@ -50,7 +50,7 @@ class DefaultParser: LaunchGateParser { // var optionalUpdate: UpdateConfiguration? // var requiredUpdate: UpdateConfiguration? // -// if let alertJSON = config["alert"] /*as? JSON*/ { +// if let alertJSON = config["alert"] as? JSON { // alert = try DefaultParser.parseAlert(alertJSON) // } // From c0ad0463a33f002f130fb01a290201c8c4c8a7bd Mon Sep 17 00:00:00 2001 From: Britney Smith Date: Wed, 14 Nov 2018 13:23:03 -0500 Subject: [PATCH 13/25] WIP - Fixed decoder initializer --- Source/LaunchGateConfiguration.swift | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Source/LaunchGateConfiguration.swift b/Source/LaunchGateConfiguration.swift index b4feb18..6847860 100755 --- a/Source/LaunchGateConfiguration.swift +++ b/Source/LaunchGateConfiguration.swift @@ -22,11 +22,10 @@ public struct LaunchGateConfiguration: Decodable { public init(from decoder: Decoder) throws { let iosContainer = try decoder.container(keyedBy: IOSRootKey.self) - let ios = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .ios) - - let alert = try ios.decode(AlertConfiguration.self, forKey: .alert) - let optionalUpdate = try ios.decode(UpdateConfiguration.self, forKey: .optionalUpdate) - let requiredUpdate = try ios.decode(UpdateConfiguration.self, forKey: .requiredUpdate) + //let ios = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .ios) + self.alert = try iosContainer.decode(AlertConfiguration.self, forKey: .alert) + self.optionalUpdate = try iosContainer.decode(UpdateConfiguration.self, forKey: .optionalUpdate) + self.requiredUpdate = try iosContainer.decode(UpdateConfiguration.self, forKey: .requiredUpdate) //let alert = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .alert) //let optionalUpdate = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .optionalUpdate) //let requiredUpdate = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .requiredUpdate) From 5065dd09c000a480e33684fe320d353e3b37ad5c Mon Sep 17 00:00:00 2001 From: Britney Smith Date: Wed, 14 Nov 2018 13:36:08 -0500 Subject: [PATCH 14/25] WIP - trying CodingKey struct --- Source/LaunchGateConfiguration.swift | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Source/LaunchGateConfiguration.swift b/Source/LaunchGateConfiguration.swift index 6847860..0a42640 100755 --- a/Source/LaunchGateConfiguration.swift +++ b/Source/LaunchGateConfiguration.swift @@ -12,16 +12,36 @@ import Foundation public struct LaunchGateConfiguration: Decodable { /// An `AlertConfiguration`, parsed from the configuration file. - var alert: AlertConfiguration? + var alert: AlertConfiguration /// An optional `UpdateConfiguration`, parsed from the configuration file. - var optionalUpdate: UpdateConfiguration? + var optionalUpdate: UpdateConfiguration /// A required `UpdateConfiguration`, parsed from the configuration file. - var requiredUpdate: UpdateConfiguration? + var requiredUpdate: UpdateConfiguration + + struct IOSRootKeys: CodingKey { + var stringValue: String + var intValue: Int? + + init?(stringValue: String) { + self.stringValue = stringValue + } + + init?(intValue: Int) { + self.intValue = intValue + self.stringValue = "\(intValue)" + } + + static func checkKeyName(to key: String) -> IOSRootKeys { + return IOSRootKeys(stringValue: key)! + } + + static let keyName = IOSRootKeys.changeKeyName(to: <#T##String#>) + } public init(from decoder: Decoder) throws { - let iosContainer = try decoder.container(keyedBy: IOSRootKey.self) + let iosContainer = try decoder.container(keyedBy: IOSRootKeys.self) //let ios = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .ios) self.alert = try iosContainer.decode(AlertConfiguration.self, forKey: .alert) self.optionalUpdate = try iosContainer.decode(UpdateConfiguration.self, forKey: .optionalUpdate) From d41da4165fab3cac70c664f75f01571f8f427dcc Mon Sep 17 00:00:00 2001 From: Britney Smith Date: Wed, 14 Nov 2018 14:09:49 -0500 Subject: [PATCH 15/25] WIP - decoding changes --- Source/LaunchGateConfiguration.swift | 29 +++++----------------------- 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/Source/LaunchGateConfiguration.swift b/Source/LaunchGateConfiguration.swift index 0a42640..c0ac2b8 100755 --- a/Source/LaunchGateConfiguration.swift +++ b/Source/LaunchGateConfiguration.swift @@ -12,36 +12,17 @@ import Foundation public struct LaunchGateConfiguration: Decodable { /// An `AlertConfiguration`, parsed from the configuration file. - var alert: AlertConfiguration + var alert: AlertConfiguration? /// An optional `UpdateConfiguration`, parsed from the configuration file. - var optionalUpdate: UpdateConfiguration + var optionalUpdate: UpdateConfiguration? /// A required `UpdateConfiguration`, parsed from the configuration file. - var requiredUpdate: UpdateConfiguration + var requiredUpdate: UpdateConfiguration? - struct IOSRootKeys: CodingKey { - var stringValue: String - var intValue: Int? - - init?(stringValue: String) { - self.stringValue = stringValue - } - - init?(intValue: Int) { - self.intValue = intValue - self.stringValue = "\(intValue)" - } - - static func checkKeyName(to key: String) -> IOSRootKeys { - return IOSRootKeys(stringValue: key)! - } - - static let keyName = IOSRootKeys.changeKeyName(to: <#T##String#>) - } public init(from decoder: Decoder) throws { - let iosContainer = try decoder.container(keyedBy: IOSRootKeys.self) + let iosContainer = try decoder.container(keyedBy: IOSRootKey.self) //let ios = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .ios) self.alert = try iosContainer.decode(AlertConfiguration.self, forKey: .alert) self.optionalUpdate = try iosContainer.decode(UpdateConfiguration.self, forKey: .optionalUpdate) @@ -51,7 +32,7 @@ public struct LaunchGateConfiguration: Decodable { //let requiredUpdate = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .requiredUpdate) } enum IOSRootKey: CodingKey { - case ios + //case ios case alert case optionalUpdate case requiredUpdate From 3d8fe1d933a91e7a038685b445b3f91cf3fa7721 Mon Sep 17 00:00:00 2001 From: Britney Smith Date: Wed, 14 Nov 2018 14:15:47 -0500 Subject: [PATCH 16/25] Changed decoding in UpdateConfiguration: accounted for possibility for all three objects to be represented in JSON --- Source/UpdateConfiguration.swift | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Source/UpdateConfiguration.swift b/Source/UpdateConfiguration.swift index 375e9a3..0beccf1 100755 --- a/Source/UpdateConfiguration.swift +++ b/Source/UpdateConfiguration.swift @@ -21,14 +21,11 @@ public struct UpdateConfiguration: Decodable, Dialogable, Rememberable { } public init(from decoder: Decoder) throws { let optionalKeyedContainer = try decoder.container(keyedBy: OptionalCodingKeys.self) - do { - version = try optionalKeyedContainer.decode(String.self, forKey: .version) - message = try optionalKeyedContainer.decode(String.self, forKey: .message) - } catch { - let requiredKeyedContainer = try decoder.container(keyedBy: RequiredCodingKeys.self) - version = try requiredKeyedContainer.decode(String.self, forKey: .version) - message = try requiredKeyedContainer.decode(String.self, forKey: .message) - } + let requiredKeyedContainer = try decoder.container(keyedBy: RequiredCodingKeys.self) + version = try optionalKeyedContainer.decode(String.self, forKey: .version) + message = try optionalKeyedContainer.decode(String.self, forKey: .message) + version = try requiredKeyedContainer.decode(String.self, forKey: .version) + message = try requiredKeyedContainer.decode(String.self, forKey: .message) } enum OptionalCodingKeys: String, CodingKey { case version = "optionalVersion" From 7f0a82ec42b1b88adf97fab9d352b0fbe8f9c600 Mon Sep 17 00:00:00 2001 From: Britney Smith Date: Wed, 14 Nov 2018 15:42:02 -0500 Subject: [PATCH 17/25] WIP - possible async issue; properties not available before parse --- Source/AlertConfiguration.swift | 2 +- Source/LaunchGate.swift | 4 +++- Source/LaunchGateConfiguration.swift | 5 ++--- Source/RemoteFileManager.swift | 2 +- Source/UpdateConfiguration.swift | 4 ++-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Source/AlertConfiguration.swift b/Source/AlertConfiguration.swift index 81717b4..1ae03b1 100755 --- a/Source/AlertConfiguration.swift +++ b/Source/AlertConfiguration.swift @@ -7,7 +7,7 @@ import Foundation -public struct AlertConfiguration: Decodable, Dialogable, Rememberable { +public class AlertConfiguration: Decodable, Dialogable, Rememberable { let message: String let blocking: Bool diff --git a/Source/LaunchGate.swift b/Source/LaunchGate.swift index 6b76076..132faa7 100755 --- a/Source/LaunchGate.swift +++ b/Source/LaunchGate.swift @@ -25,6 +25,7 @@ public class LaunchGate { /// Manager object for the various alert dialogs var dialogManager: DialogManager! + //var config: LaunchGateConfiguration! // MARK: - Public API /** @@ -63,7 +64,8 @@ public class LaunchGate { */ func performCheck(_ remoteFileManager: RemoteFileManager) { remoteFileManager.fetchRemoteFile { (jsonData) -> Void in - if let config = self.parser.parse(jsonData) { + if let config: LaunchGateConfiguration = self.parser.parse(jsonData) { + print("Config: \(config)") self.displayDialogIfNecessary(config, dialogManager: self.dialogManager) } } diff --git a/Source/LaunchGateConfiguration.swift b/Source/LaunchGateConfiguration.swift index c0ac2b8..6206b8a 100755 --- a/Source/LaunchGateConfiguration.swift +++ b/Source/LaunchGateConfiguration.swift @@ -9,7 +9,7 @@ import Foundation /// The configuration object that should be created as the result of parsing the remote configuration file. -public struct LaunchGateConfiguration: Decodable { +public class LaunchGateConfiguration: Decodable { /// An `AlertConfiguration`, parsed from the configuration file. var alert: AlertConfiguration? @@ -20,8 +20,7 @@ public struct LaunchGateConfiguration: Decodable { /// A required `UpdateConfiguration`, parsed from the configuration file. var requiredUpdate: UpdateConfiguration? - - public init(from decoder: Decoder) throws { + required public init(from decoder: Decoder) throws { let iosContainer = try decoder.container(keyedBy: IOSRootKey.self) //let ios = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .ios) self.alert = try iosContainer.decode(AlertConfiguration.self, forKey: .alert) diff --git a/Source/RemoteFileManager.swift b/Source/RemoteFileManager.swift index 0e4f797..567b51a 100755 --- a/Source/RemoteFileManager.swift +++ b/Source/RemoteFileManager.swift @@ -23,7 +23,7 @@ class RemoteFileManager { func performRemoteFileRequest(_ session: URLSession, url: URL, responseHandler: @escaping (_ data: Data) -> Void) { let task = session.dataTask(with: url) { data, response, error in if let error = error { - print("LaunchGate — Error: \(error.localizedDescription)") + print("LaunchGate — Error2: \(error.localizedDescription)") } guard response != nil else { print("LaunchGate - Error because there is no response") diff --git a/Source/UpdateConfiguration.swift b/Source/UpdateConfiguration.swift index 0beccf1..9e7a683 100755 --- a/Source/UpdateConfiguration.swift +++ b/Source/UpdateConfiguration.swift @@ -8,7 +8,7 @@ import Foundation -public struct UpdateConfiguration: Decodable, Dialogable, Rememberable { +public class UpdateConfiguration: Decodable, Dialogable, Rememberable { var version: String var message: String @@ -19,7 +19,7 @@ public struct UpdateConfiguration: Decodable, Dialogable, Rememberable { self.version = version self.message = message } - public init(from decoder: Decoder) throws { + required public init(from decoder: Decoder) throws { let optionalKeyedContainer = try decoder.container(keyedBy: OptionalCodingKeys.self) let requiredKeyedContainer = try decoder.container(keyedBy: RequiredCodingKeys.self) version = try optionalKeyedContainer.decode(String.self, forKey: .version) From eeb19bd166e27430f5f9ad7d7324d3f4a989a9bd Mon Sep 17 00:00:00 2001 From: Britney Smith Date: Thu, 15 Nov 2018 10:06:55 -0500 Subject: [PATCH 18/25] Preparing changes for review --- Source/AlertConfiguration.swift | 2 +- Source/DefaultParser.swift | 3 ++- Source/LaunchGateConfiguration.swift | 4 ++-- Source/UpdateConfiguration.swift | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Source/AlertConfiguration.swift b/Source/AlertConfiguration.swift index 1ae03b1..81717b4 100755 --- a/Source/AlertConfiguration.swift +++ b/Source/AlertConfiguration.swift @@ -7,7 +7,7 @@ import Foundation -public class AlertConfiguration: Decodable, Dialogable, Rememberable { +public struct AlertConfiguration: Decodable, Dialogable, Rememberable { let message: String let blocking: Bool diff --git a/Source/DefaultParser.swift b/Source/DefaultParser.swift index 728cee0..e00fbca 100755 --- a/Source/DefaultParser.swift +++ b/Source/DefaultParser.swift @@ -75,7 +75,7 @@ class DefaultParser: LaunchGateParser { // // return nil // } -// +// --- Experiments --- // private static func parseAlert(_ jsonData: Data) -> AlertConfiguration? { // do { // let decoder = JSONDecoder() @@ -106,6 +106,7 @@ class DefaultParser: LaunchGateParser { // return nil // } // } +// --- End of Experiments --- // private static func parseAlert(_ json: JSON) throws -> AlertConfiguration? { // guard let message = json["message"] as? String else { throw Error.unableToParseAlert } // guard let blocking = json["blocking"] as? Bool else { throw Error.unableToParseAlert } diff --git a/Source/LaunchGateConfiguration.swift b/Source/LaunchGateConfiguration.swift index 6206b8a..d7e1e5b 100755 --- a/Source/LaunchGateConfiguration.swift +++ b/Source/LaunchGateConfiguration.swift @@ -9,7 +9,7 @@ import Foundation /// The configuration object that should be created as the result of parsing the remote configuration file. -public class LaunchGateConfiguration: Decodable { +public struct LaunchGateConfiguration: Decodable { /// An `AlertConfiguration`, parsed from the configuration file. var alert: AlertConfiguration? @@ -20,7 +20,7 @@ public class LaunchGateConfiguration: Decodable { /// A required `UpdateConfiguration`, parsed from the configuration file. var requiredUpdate: UpdateConfiguration? - required public init(from decoder: Decoder) throws { + public init(from decoder: Decoder) throws { let iosContainer = try decoder.container(keyedBy: IOSRootKey.self) //let ios = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .ios) self.alert = try iosContainer.decode(AlertConfiguration.self, forKey: .alert) diff --git a/Source/UpdateConfiguration.swift b/Source/UpdateConfiguration.swift index 9e7a683..1202d7f 100755 --- a/Source/UpdateConfiguration.swift +++ b/Source/UpdateConfiguration.swift @@ -8,7 +8,7 @@ import Foundation -public class UpdateConfiguration: Decodable, Dialogable, Rememberable { +public struct UpdateConfiguration: Decodable, Dialogable, Rememberable { var version: String var message: String @@ -19,7 +19,7 @@ public class UpdateConfiguration: Decodable, Dialogable, Rememberable { self.version = version self.message = message } - required public init(from decoder: Decoder) throws { + public init(from decoder: Decoder) throws { let optionalKeyedContainer = try decoder.container(keyedBy: OptionalCodingKeys.self) let requiredKeyedContainer = try decoder.container(keyedBy: RequiredCodingKeys.self) version = try optionalKeyedContainer.decode(String.self, forKey: .version) From 0155f527f2a0ac04e9fbeff991a1ebf3362775e3 Mon Sep 17 00:00:00 2001 From: Britney Smith Date: Thu, 15 Nov 2018 15:30:06 -0500 Subject: [PATCH 19/25] WIP - decoded root object --- Source/AlertConfiguration.swift | 6 +++--- Source/DefaultParser.swift | 2 +- Source/DialogManager.swift | 8 ++++---- Source/LaunchGate.swift | 8 ++++---- Source/LaunchGateConfiguration.swift | 16 ++++++++-------- Source/UpdateConfiguration.swift | 6 +++--- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Source/AlertConfiguration.swift b/Source/AlertConfiguration.swift index 81717b4..c20c03c 100755 --- a/Source/AlertConfiguration.swift +++ b/Source/AlertConfiguration.swift @@ -9,8 +9,8 @@ import Foundation public struct AlertConfiguration: Decodable, Dialogable, Rememberable { - let message: String - let blocking: Bool + let message: String? + let blocking: Bool? init?(message: String, blocking: Bool) { guard !message.isEmpty else { return nil } @@ -26,7 +26,7 @@ public struct AlertConfiguration: Decodable, Dialogable, Rememberable { } func rememberString() -> String { - return self.message + return self.message! ///unwrap } } diff --git a/Source/DefaultParser.swift b/Source/DefaultParser.swift index e00fbca..468d2d8 100755 --- a/Source/DefaultParser.swift +++ b/Source/DefaultParser.swift @@ -36,7 +36,7 @@ class DefaultParser: LaunchGateParser { let result = try decoder.decode(LaunchGateConfiguration.self, from: jsonData) return result } catch let error { - print("LaunchGate — Error: \(error.localizedDescription)") + print("LaunchGate — Error: \(error)") } return nil } diff --git a/Source/DialogManager.swift b/Source/DialogManager.swift index 1fe1a6b..691223f 100755 --- a/Source/DialogManager.swift +++ b/Source/DialogManager.swift @@ -10,7 +10,7 @@ import Foundation import UIKit protocol Dialogable { - var message: String { get } + var message: String? { get } } class DialogManager { @@ -24,7 +24,7 @@ class DialogManager { } func displayAlertDialog(_ alertConfig: RememberableDialogSubject, blocking: Bool) { - let dialog = createAlertController(.alert(blocking: blocking), message: alertConfig.message) + let dialog = createAlertController(.alert(blocking: blocking), message: alertConfig.message!) ///unwrap displayAlertController(dialog) { () -> Void in if !blocking { @@ -34,13 +34,13 @@ class DialogManager { } func displayRequiredUpdateDialog(_ updateConfig: Dialogable, updateURL: URL) { - let dialog = createAlertController(.requiredUpdate(updateURL: updateURL), message: updateConfig.message) + let dialog = createAlertController(.requiredUpdate(updateURL: updateURL), message: updateConfig.message!) ///unwrap displayAlertController(dialog, completion: nil) } func displayOptionalUpdateDialog(_ updateConfig: RememberableDialogSubject, updateURL: URL) { - let dialog = createAlertController(.optionalUpdate(updateURL: updateURL), message: updateConfig.message) + let dialog = createAlertController(.optionalUpdate(updateURL: updateURL), message: updateConfig.message!) ///unwrap displayAlertController(dialog) { () -> Void in Memory.remember(updateConfig) diff --git a/Source/LaunchGate.swift b/Source/LaunchGate.swift index 132faa7..1f9e09d 100755 --- a/Source/LaunchGate.swift +++ b/Source/LaunchGate.swift @@ -89,7 +89,7 @@ public class LaunchGate { } } else if let alert = config.alert { if shouldShowAlertDialog(alert) { - dialogManager.displayAlertDialog(alert, blocking: alert.blocking) + dialogManager.displayAlertDialog(alert, blocking: alert.blocking!) ///unwrap } } } @@ -102,7 +102,7 @@ public class LaunchGate { - Returns: `true`, if an alert dialog should be displayed; `false`, if not. */ func shouldShowAlertDialog(_ alertConfig: AlertConfiguration) -> Bool { - return alertConfig.blocking || alertConfig.isNotRemembered() + return alertConfig.blocking! || alertConfig.isNotRemembered() ///unwrap } /** @@ -115,7 +115,7 @@ public class LaunchGate { func shouldShowOptionalUpdateDialog(_ updateConfig: UpdateConfiguration, appVersion: String) -> Bool { guard updateConfig.isNotRemembered() else { return false } - return appVersion < updateConfig.version + return appVersion < updateConfig.version! ///unwrap } /** @@ -126,7 +126,7 @@ public class LaunchGate { - Returns: `true`, if a required update dialog should be displayed; `false`, if not. */ func shouldShowRequiredUpdateDialog(_ updateConfig: UpdateConfiguration, appVersion: String) -> Bool { - return appVersion < updateConfig.version + return appVersion < updateConfig.version! ///unwrap } func currentAppVersion() -> String? { diff --git a/Source/LaunchGateConfiguration.swift b/Source/LaunchGateConfiguration.swift index d7e1e5b..65e844d 100755 --- a/Source/LaunchGateConfiguration.swift +++ b/Source/LaunchGateConfiguration.swift @@ -23,18 +23,18 @@ public struct LaunchGateConfiguration: Decodable { public init(from decoder: Decoder) throws { let iosContainer = try decoder.container(keyedBy: IOSRootKey.self) //let ios = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .ios) - self.alert = try iosContainer.decode(AlertConfiguration.self, forKey: .alert) - self.optionalUpdate = try iosContainer.decode(UpdateConfiguration.self, forKey: .optionalUpdate) - self.requiredUpdate = try iosContainer.decode(UpdateConfiguration.self, forKey: .requiredUpdate) + //self.alert = try iosContainer.decode(AlertConfiguration.self, forKey: .alert) + //self.optionalUpdate = try iosContainer.decode(UpdateConfiguration.self, forKey: .optionalUpdate) + //self.requiredUpdate = try iosContainer.decode(UpdateConfiguration.self, forKey: .requiredUpdate) //let alert = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .alert) //let optionalUpdate = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .optionalUpdate) //let requiredUpdate = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .requiredUpdate) } - enum IOSRootKey: CodingKey { - //case ios - case alert - case optionalUpdate - case requiredUpdate + enum IOSRootKey: String, CodingKey { + case ios + //case alert + //case optionalUpdate + //case requiredUpdate } // enum ConfigCodingKeys: String, CodingKey { // case alert diff --git a/Source/UpdateConfiguration.swift b/Source/UpdateConfiguration.swift index 1202d7f..61e16c8 100755 --- a/Source/UpdateConfiguration.swift +++ b/Source/UpdateConfiguration.swift @@ -9,8 +9,8 @@ import Foundation public struct UpdateConfiguration: Decodable, Dialogable, Rememberable { - var version: String - var message: String + var version: String? + var message: String? init?(version: String, message: String) { guard !version.isEmpty else { return nil } @@ -43,7 +43,7 @@ public struct UpdateConfiguration: Decodable, Dialogable, Rememberable { } func rememberString() -> String { - return self.version + return self.version! ///unwrap } } From ddb66edcc5fee18eaf5ea5e6f3745ea269fbaebc Mon Sep 17 00:00:00 2001 From: Britney Smith Date: Thu, 15 Nov 2018 16:09:12 -0500 Subject: [PATCH 20/25] Removed optionals; decoded nested objects 'alert', 'optionalUpdate' and 'requiredUpdate' with JSONDecoder --- Source/AlertConfiguration.swift | 6 +- Source/DefaultParser.swift | 142 +++++++++++++-------------- Source/DialogManager.swift | 8 +- Source/LaunchGate.swift | 8 +- Source/LaunchGateConfiguration.swift | 32 +++--- Source/UpdateConfiguration.swift | 18 ++-- 6 files changed, 107 insertions(+), 107 deletions(-) diff --git a/Source/AlertConfiguration.swift b/Source/AlertConfiguration.swift index c20c03c..81717b4 100755 --- a/Source/AlertConfiguration.swift +++ b/Source/AlertConfiguration.swift @@ -9,8 +9,8 @@ import Foundation public struct AlertConfiguration: Decodable, Dialogable, Rememberable { - let message: String? - let blocking: Bool? + let message: String + let blocking: Bool init?(message: String, blocking: Bool) { guard !message.isEmpty else { return nil } @@ -26,7 +26,7 @@ public struct AlertConfiguration: Decodable, Dialogable, Rememberable { } func rememberString() -> String { - return self.message! ///unwrap + return self.message } } diff --git a/Source/DefaultParser.swift b/Source/DefaultParser.swift index 468d2d8..e8639ed 100755 --- a/Source/DefaultParser.swift +++ b/Source/DefaultParser.swift @@ -30,82 +30,82 @@ class DefaultParser: LaunchGateParser { } } } - func parse(_ jsonData: Data) -> LaunchGateConfiguration? { - do { - let decoder = JSONDecoder() - let result = try decoder.decode(LaunchGateConfiguration.self, from: jsonData) - return result - } catch let error { - print("LaunchGate — Error: \(error)") - } - return nil - } -// func parse(_ jsonData: Data) -> LaunchGateConfiguration? { -// do { -// let jsonData = try JSONSerialization.jsonObject(with: jsonData, options: []) -// guard let json = jsonData as? JSON else { throw Error.unableToParseConfigurationObject } -// guard let config = json["ios"] else { throw Error.unableToParseConfigurationObject } -// -// var alert: AlertConfiguration? -// var optionalUpdate: UpdateConfiguration? -// var requiredUpdate: UpdateConfiguration? -// -// if let alertJSON = config["alert"] as? JSON { -// alert = try DefaultParser.parseAlert(alertJSON) -// } -// -// if let optionalUpdateJSON = config["optionalUpdate"] as? JSON { -// optionalUpdate = try DefaultParser.parseOptionalUpdate(optionalUpdateJSON) -// } -// -// if let requiredUpdateJSON = config["requiredUpdate"] as? JSON { -// requiredUpdate = try DefaultParser.parseRequiredUpdate(requiredUpdateJSON) -// } -// -// return LaunchGateConfiguration(alert: alert, optionalUpdate: optionalUpdate, requiredUpdate: requiredUpdate) -// } catch let error as DefaultParser.Error { -// print("LaunchGate — Error: \(error)") -// } catch let error as NSError { -// print("LaunchGate — Error: \(error.localizedDescription)") -// -// if let recoverySuggestion = error.localizedRecoverySuggestion { -// print(recoverySuggestion) -// } -// } -// -// return nil -// } -// --- Experiments --- -// private static func parseAlert(_ jsonData: Data) -> AlertConfiguration? { -// do { -// let decoder = JSONDecoder() -// let result = try decoder.decode(AlertConfiguration.self, from: jsonData) -// return result -// } catch { -// print(error) -// return nil -// } -// } -// private static func parseOptionalUpdate(_ jsonData: Data) -> UpdateConfiguration? { -// do { -// let decoder = JSONDecoder() -// let result = try decoder.decode(UpdateConfiguration.self, from: jsonData) -// return result -// } catch { -// print(error) -// return nil -// } -// } -// private static func parseRequiredUpdate(_ jsonData: Data) -> UpdateConfiguration? { +// func parse(_ jsonData: Data) -> LaunchGateConfiguration? { // do { // let decoder = JSONDecoder() -// let result = try decoder.decode(UpdateConfiguration.self, from: jsonData) +// let result = try decoder.decode(LaunchGateConfiguration.self, from: jsonData) // return result -// } catch { -// print(error) -// return nil +// } catch let error { +// print("LaunchGate — Error: \(error)") // } +// return nil // } + func parse(_ jsonData: Data) -> LaunchGateConfiguration? { + do { + let jsonData = try JSONSerialization.jsonObject(with: jsonData, options: []) + guard let json = jsonData as? JSON else { throw Error.unableToParseConfigurationObject } + guard let config = json["ios"] else { throw Error.unableToParseConfigurationObject } + + var alert: AlertConfiguration? + var optionalUpdate: UpdateConfiguration? + var requiredUpdate: UpdateConfiguration? + + if let alertJSON = config["alert"] as? Data { + alert = try DefaultParser.parseAlert(alertJSON) + } + + if let optionalUpdateJSON = config["optionalUpdate"] as? Data { + optionalUpdate = try DefaultParser.parseOptionalUpdate(optionalUpdateJSON) + } + + if let requiredUpdateJSON = config["requiredUpdate"] as? Data { + requiredUpdate = try DefaultParser.parseRequiredUpdate(requiredUpdateJSON) + } + + return LaunchGateConfiguration(alert: alert, optionalUpdate: optionalUpdate, requiredUpdate: requiredUpdate) + } catch let error as DefaultParser.Error { + print("LaunchGate — Error: \(error)") + } catch let error as NSError { + print("LaunchGate — Error: \(error.localizedDescription)") + + if let recoverySuggestion = error.localizedRecoverySuggestion { + print(recoverySuggestion) + } + } + + return nil + } +// --- Experiments --- + private static func parseAlert(_ jsonData: Data) -> AlertConfiguration? { + do { + let decoder = JSONDecoder() + let result = try decoder.decode(AlertConfiguration.self, from: jsonData) + return result + } catch { + print(error) + return nil + } + } + private static func parseOptionalUpdate(_ jsonData: Data) -> UpdateConfiguration? { + do { + let decoder = JSONDecoder() + let result = try decoder.decode(UpdateConfiguration.self, from: jsonData) + return result + } catch { + print(error) + return nil + } + } + private static func parseRequiredUpdate(_ jsonData: Data) -> UpdateConfiguration? { + do { + let decoder = JSONDecoder() + let result = try decoder.decode(UpdateConfiguration.self, from: jsonData) + return result + } catch { + print(error) + return nil + } + } // --- End of Experiments --- // private static func parseAlert(_ json: JSON) throws -> AlertConfiguration? { // guard let message = json["message"] as? String else { throw Error.unableToParseAlert } diff --git a/Source/DialogManager.swift b/Source/DialogManager.swift index 691223f..1b28820 100755 --- a/Source/DialogManager.swift +++ b/Source/DialogManager.swift @@ -10,7 +10,7 @@ import Foundation import UIKit protocol Dialogable { - var message: String? { get } + var message: String { get } } class DialogManager { @@ -24,7 +24,7 @@ class DialogManager { } func displayAlertDialog(_ alertConfig: RememberableDialogSubject, blocking: Bool) { - let dialog = createAlertController(.alert(blocking: blocking), message: alertConfig.message!) ///unwrap + let dialog = createAlertController(.alert(blocking: blocking), message: alertConfig.message) displayAlertController(dialog) { () -> Void in if !blocking { @@ -34,13 +34,13 @@ class DialogManager { } func displayRequiredUpdateDialog(_ updateConfig: Dialogable, updateURL: URL) { - let dialog = createAlertController(.requiredUpdate(updateURL: updateURL), message: updateConfig.message!) ///unwrap + let dialog = createAlertController(.requiredUpdate(updateURL: updateURL), message: updateConfig.message) displayAlertController(dialog, completion: nil) } func displayOptionalUpdateDialog(_ updateConfig: RememberableDialogSubject, updateURL: URL) { - let dialog = createAlertController(.optionalUpdate(updateURL: updateURL), message: updateConfig.message!) ///unwrap + let dialog = createAlertController(.optionalUpdate(updateURL: updateURL), message: updateConfig.message) displayAlertController(dialog) { () -> Void in Memory.remember(updateConfig) diff --git a/Source/LaunchGate.swift b/Source/LaunchGate.swift index 1f9e09d..132faa7 100755 --- a/Source/LaunchGate.swift +++ b/Source/LaunchGate.swift @@ -89,7 +89,7 @@ public class LaunchGate { } } else if let alert = config.alert { if shouldShowAlertDialog(alert) { - dialogManager.displayAlertDialog(alert, blocking: alert.blocking!) ///unwrap + dialogManager.displayAlertDialog(alert, blocking: alert.blocking) } } } @@ -102,7 +102,7 @@ public class LaunchGate { - Returns: `true`, if an alert dialog should be displayed; `false`, if not. */ func shouldShowAlertDialog(_ alertConfig: AlertConfiguration) -> Bool { - return alertConfig.blocking! || alertConfig.isNotRemembered() ///unwrap + return alertConfig.blocking || alertConfig.isNotRemembered() } /** @@ -115,7 +115,7 @@ public class LaunchGate { func shouldShowOptionalUpdateDialog(_ updateConfig: UpdateConfiguration, appVersion: String) -> Bool { guard updateConfig.isNotRemembered() else { return false } - return appVersion < updateConfig.version! ///unwrap + return appVersion < updateConfig.version } /** @@ -126,7 +126,7 @@ public class LaunchGate { - Returns: `true`, if a required update dialog should be displayed; `false`, if not. */ func shouldShowRequiredUpdateDialog(_ updateConfig: UpdateConfiguration, appVersion: String) -> Bool { - return appVersion < updateConfig.version! ///unwrap + return appVersion < updateConfig.version } func currentAppVersion() -> String? { diff --git a/Source/LaunchGateConfiguration.swift b/Source/LaunchGateConfiguration.swift index 65e844d..254a89f 100755 --- a/Source/LaunchGateConfiguration.swift +++ b/Source/LaunchGateConfiguration.swift @@ -20,22 +20,22 @@ public struct LaunchGateConfiguration: Decodable { /// A required `UpdateConfiguration`, parsed from the configuration file. var requiredUpdate: UpdateConfiguration? - public init(from decoder: Decoder) throws { - let iosContainer = try decoder.container(keyedBy: IOSRootKey.self) - //let ios = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .ios) - //self.alert = try iosContainer.decode(AlertConfiguration.self, forKey: .alert) - //self.optionalUpdate = try iosContainer.decode(UpdateConfiguration.self, forKey: .optionalUpdate) - //self.requiredUpdate = try iosContainer.decode(UpdateConfiguration.self, forKey: .requiredUpdate) - //let alert = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .alert) - //let optionalUpdate = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .optionalUpdate) - //let requiredUpdate = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .requiredUpdate) - } - enum IOSRootKey: String, CodingKey { - case ios - //case alert - //case optionalUpdate - //case requiredUpdate - } +// public init(from decoder: Decoder) throws { +// let iosContainer = try decoder.container(keyedBy: IOSRootKey.self) +// //let ios = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .ios) +// //self.alert = try iosContainer.decode(AlertConfiguration.self, forKey: .alert) +// //self.optionalUpdate = try iosContainer.decode(UpdateConfiguration.self, forKey: .optionalUpdate) +// //self.requiredUpdate = try iosContainer.decode(UpdateConfiguration.self, forKey: .requiredUpdate) +// //let alert = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .alert) +// //let optionalUpdate = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .optionalUpdate) +// //let requiredUpdate = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .requiredUpdate) +// } +// enum IOSRootKey: String, CodingKey { +// case ios +// //case alert +// //case optionalUpdate +// //case requiredUpdate +// } // enum ConfigCodingKeys: String, CodingKey { // case alert // case optionalUpdate diff --git a/Source/UpdateConfiguration.swift b/Source/UpdateConfiguration.swift index 61e16c8..7741cac 100755 --- a/Source/UpdateConfiguration.swift +++ b/Source/UpdateConfiguration.swift @@ -9,8 +9,8 @@ import Foundation public struct UpdateConfiguration: Decodable, Dialogable, Rememberable { - var version: String? - var message: String? + var version: String + var message: String init?(version: String, message: String) { guard !version.isEmpty else { return nil } @@ -20,12 +20,12 @@ public struct UpdateConfiguration: Decodable, Dialogable, Rememberable { self.message = message } public init(from decoder: Decoder) throws { - let optionalKeyedContainer = try decoder.container(keyedBy: OptionalCodingKeys.self) - let requiredKeyedContainer = try decoder.container(keyedBy: RequiredCodingKeys.self) - version = try optionalKeyedContainer.decode(String.self, forKey: .version) - message = try optionalKeyedContainer.decode(String.self, forKey: .message) - version = try requiredKeyedContainer.decode(String.self, forKey: .version) - message = try requiredKeyedContainer.decode(String.self, forKey: .message) + let optionalKeyedContainer = try? decoder.container(keyedBy: OptionalCodingKeys.self) + let requiredKeyedContainer = try? decoder.container(keyedBy: RequiredCodingKeys.self) + version = try optionalKeyedContainer!.decode(String.self, forKey: .version) + message = try optionalKeyedContainer!.decode(String.self, forKey: .message) + version = try requiredKeyedContainer!.decode(String.self, forKey: .version) + message = try requiredKeyedContainer!.decode(String.self, forKey: .message) } enum OptionalCodingKeys: String, CodingKey { case version = "optionalVersion" @@ -43,7 +43,7 @@ public struct UpdateConfiguration: Decodable, Dialogable, Rememberable { } func rememberString() -> String { - return self.version! ///unwrap + return self.version } } From 358a5fe0c1d1273e08224b37de9797c26588e2ed Mon Sep 17 00:00:00 2001 From: Britney Smith Date: Thu, 15 Nov 2018 16:22:03 -0500 Subject: [PATCH 21/25] WIP - parsing --- Source/DefaultParser.swift | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/Source/DefaultParser.swift b/Source/DefaultParser.swift index e8639ed..3aa1150 100755 --- a/Source/DefaultParser.swift +++ b/Source/DefaultParser.swift @@ -42,6 +42,7 @@ class DefaultParser: LaunchGateParser { // } func parse(_ jsonData: Data) -> LaunchGateConfiguration? { do { + print("Parsing...") let jsonData = try JSONSerialization.jsonObject(with: jsonData, options: []) guard let json = jsonData as? JSON else { throw Error.unableToParseConfigurationObject } guard let config = json["ios"] else { throw Error.unableToParseConfigurationObject } @@ -50,17 +51,26 @@ class DefaultParser: LaunchGateParser { var optionalUpdate: UpdateConfiguration? var requiredUpdate: UpdateConfiguration? - if let alertJSON = config["alert"] as? Data { + guard let alertJSON = config["alert"] as? Data else { + print("No alert") + return nil } alert = try DefaultParser.parseAlert(alertJSON) - } + print("Alert: \(alert!)") + - if let optionalUpdateJSON = config["optionalUpdate"] as? Data { + guard let optionalUpdateJSON = config["optionalUpdate"] as? Data else { + print("No optional update") + return nil } optionalUpdate = try DefaultParser.parseOptionalUpdate(optionalUpdateJSON) - } + print("Optional Update: \(optionalUpdate!)") + - if let requiredUpdateJSON = config["requiredUpdate"] as? Data { + guard let requiredUpdateJSON = config["requiredUpdate"] as? Data else { + print("No required update") + return nil } requiredUpdate = try DefaultParser.parseRequiredUpdate(requiredUpdateJSON) - } + print("Required Update: \(requiredUpdate!)") + return LaunchGateConfiguration(alert: alert, optionalUpdate: optionalUpdate, requiredUpdate: requiredUpdate) } catch let error as DefaultParser.Error { From e7515428fd6da66ae23ab9fdc594558860f4a2f5 Mon Sep 17 00:00:00 2001 From: Britney Smith Date: Thu, 15 Nov 2018 17:16:30 -0500 Subject: [PATCH 22/25] WIP - at this point, data is parsed, still with JSONSerialization --- Source/DefaultParser.swift | 120 ++++++++++++++++++------------------- 1 file changed, 57 insertions(+), 63 deletions(-) diff --git a/Source/DefaultParser.swift b/Source/DefaultParser.swift index 3aa1150..4da6459 100755 --- a/Source/DefaultParser.swift +++ b/Source/DefaultParser.swift @@ -50,27 +50,21 @@ class DefaultParser: LaunchGateParser { var alert: AlertConfiguration? var optionalUpdate: UpdateConfiguration? var requiredUpdate: UpdateConfiguration? - - guard let alertJSON = config["alert"] as? Data else { - print("No alert") - return nil } + + if let alertJSON = config["alert"] as? JSON { alert = try DefaultParser.parseAlert(alertJSON) print("Alert: \(alert!)") - + } - guard let optionalUpdateJSON = config["optionalUpdate"] as? Data else { - print("No optional update") - return nil } + if let optionalUpdateJSON = config["optionalUpdate"] as? JSON { optionalUpdate = try DefaultParser.parseOptionalUpdate(optionalUpdateJSON) print("Optional Update: \(optionalUpdate!)") - + } - guard let requiredUpdateJSON = config["requiredUpdate"] as? Data else { - print("No required update") - return nil } + if let requiredUpdateJSON = config["requiredUpdate"] as? JSON { requiredUpdate = try DefaultParser.parseRequiredUpdate(requiredUpdateJSON) print("Required Update: \(requiredUpdate!)") - + } return LaunchGateConfiguration(alert: alert, optionalUpdate: optionalUpdate, requiredUpdate: requiredUpdate) } catch let error as DefaultParser.Error { @@ -86,56 +80,56 @@ class DefaultParser: LaunchGateParser { return nil } // --- Experiments --- - private static func parseAlert(_ jsonData: Data) -> AlertConfiguration? { - do { - let decoder = JSONDecoder() - let result = try decoder.decode(AlertConfiguration.self, from: jsonData) - return result - } catch { - print(error) - return nil - } - } - private static func parseOptionalUpdate(_ jsonData: Data) -> UpdateConfiguration? { - do { - let decoder = JSONDecoder() - let result = try decoder.decode(UpdateConfiguration.self, from: jsonData) - return result - } catch { - print(error) - return nil - } - } - private static func parseRequiredUpdate(_ jsonData: Data) -> UpdateConfiguration? { - do { - let decoder = JSONDecoder() - let result = try decoder.decode(UpdateConfiguration.self, from: jsonData) - return result - } catch { - print(error) - return nil - } - } +// private static func parseAlert(_ jsonData: Data) -> AlertConfiguration? { +// do { +// let decoder = JSONDecoder() +// let result = try decoder.decode(AlertConfiguration.self, from: jsonData) +// return result +// } catch { +// print(error) +// return nil +// } +// } +// private static func parseOptionalUpdate(_ jsonData: Data) -> UpdateConfiguration? { +// do { +// let decoder = JSONDecoder() +// let result = try decoder.decode(UpdateConfiguration.self, from: jsonData) +// return result +// } catch { +// print(error) +// return nil +// } +// } +// private static func parseRequiredUpdate(_ jsonData: Data) -> UpdateConfiguration? { +// do { +// let decoder = JSONDecoder() +// let result = try decoder.decode(UpdateConfiguration.self, from: jsonData) +// return result +// } catch { +// print(error) +// return nil +// } +// } // --- End of Experiments --- -// private static func parseAlert(_ json: JSON) throws -> AlertConfiguration? { -// guard let message = json["message"] as? String else { throw Error.unableToParseAlert } -// guard let blocking = json["blocking"] as? Bool else { throw Error.unableToParseAlert } -// -// return AlertConfiguration(message: message, blocking: blocking) -// } -// -// private static func parseOptionalUpdate(_ json: JSON) throws -> UpdateConfiguration? { -// guard let version = json["optionalVersion"] as? String else { throw Error.unableToParseOptionalUpdate } -// guard let message = json["message"] as? String else { throw Error.unableToParseOptionalUpdate } -// -// return UpdateConfiguration(version: version, message: message) -// } -// -// private static func parseRequiredUpdate(_ json: JSON) throws -> UpdateConfiguration? { -// guard let version = json["minimumVersion"] as? String else { throw Error.unableToParseRequiredUpdate } -// guard let message = json["message"] as? String else { throw Error.unableToParseRequiredUpdate } -// -// return UpdateConfiguration(version: version, message: message) -// } + private static func parseAlert(_ json: JSON) throws -> AlertConfiguration? { + guard let message = json["message"] as? String else { throw Error.unableToParseAlert } + guard let blocking = json["blocking"] as? Bool else { throw Error.unableToParseAlert } + + return AlertConfiguration(message: message, blocking: blocking) + } + + private static func parseOptionalUpdate(_ json: JSON) throws -> UpdateConfiguration? { + guard let version = json["optionalVersion"] as? String else { throw Error.unableToParseOptionalUpdate } + guard let message = json["message"] as? String else { throw Error.unableToParseOptionalUpdate } + + return UpdateConfiguration(version: version, message: message) + } + + private static func parseRequiredUpdate(_ json: JSON) throws -> UpdateConfiguration? { + guard let version = json["minimumVersion"] as? String else { throw Error.unableToParseRequiredUpdate } + guard let message = json["message"] as? String else { throw Error.unableToParseRequiredUpdate } + + return UpdateConfiguration(version: version, message: message) + } } From 3291550ab954eced537c9cca8be1d581a384cfd2 Mon Sep 17 00:00:00 2001 From: Britney Smith Date: Fri, 16 Nov 2018 08:56:51 -0500 Subject: [PATCH 23/25] WIP - Changed manual decoding --- Source/DefaultParser.swift | 118 +++++++++++++-------------- Source/LaunchGateConfiguration.swift | 34 +++----- Source/UpdateConfiguration.swift | 22 +++-- 3 files changed, 88 insertions(+), 86 deletions(-) diff --git a/Source/DefaultParser.swift b/Source/DefaultParser.swift index 4da6459..5ce4170 100755 --- a/Source/DefaultParser.swift +++ b/Source/DefaultParser.swift @@ -40,45 +40,45 @@ class DefaultParser: LaunchGateParser { // } // return nil // } - func parse(_ jsonData: Data) -> LaunchGateConfiguration? { - do { - print("Parsing...") - let jsonData = try JSONSerialization.jsonObject(with: jsonData, options: []) - guard let json = jsonData as? JSON else { throw Error.unableToParseConfigurationObject } - guard let config = json["ios"] else { throw Error.unableToParseConfigurationObject } - - var alert: AlertConfiguration? - var optionalUpdate: UpdateConfiguration? - var requiredUpdate: UpdateConfiguration? - - if let alertJSON = config["alert"] as? JSON { - alert = try DefaultParser.parseAlert(alertJSON) - print("Alert: \(alert!)") - } - - if let optionalUpdateJSON = config["optionalUpdate"] as? JSON { - optionalUpdate = try DefaultParser.parseOptionalUpdate(optionalUpdateJSON) - print("Optional Update: \(optionalUpdate!)") - } - - if let requiredUpdateJSON = config["requiredUpdate"] as? JSON { - requiredUpdate = try DefaultParser.parseRequiredUpdate(requiredUpdateJSON) - print("Required Update: \(requiredUpdate!)") - } - - return LaunchGateConfiguration(alert: alert, optionalUpdate: optionalUpdate, requiredUpdate: requiredUpdate) - } catch let error as DefaultParser.Error { - print("LaunchGate — Error: \(error)") - } catch let error as NSError { - print("LaunchGate — Error: \(error.localizedDescription)") - - if let recoverySuggestion = error.localizedRecoverySuggestion { - print(recoverySuggestion) - } - } - - return nil - } +// func parse(_ jsonData: Data) -> LaunchGateConfiguration? { +// do { +// print("Parsing...") +// let jsonData = try JSONSerialization.jsonObject(with: jsonData, options: []) +// guard let json = jsonData as? JSON else { throw Error.unableToParseConfigurationObject } +// guard let config = json["ios"] else { throw Error.unableToParseConfigurationObject } +// +// var alert: AlertConfiguration? +// var optionalUpdate: UpdateConfiguration? +// var requiredUpdate: UpdateConfiguration? +// +// if let alertJSON = config["alert"] as? JSON { +// alert = try DefaultParser.parseAlert(alertJSON) +// print("Alert: \(alert!)") +// } +// +// if let optionalUpdateJSON = config["optionalUpdate"] as? JSON { +// optionalUpdate = try DefaultParser.parseOptionalUpdate(optionalUpdateJSON) +// print("Optional Update: \(optionalUpdate!)") +// } +// +// if let requiredUpdateJSON = config["requiredUpdate"] as? JSON { +// requiredUpdate = try DefaultParser.parseRequiredUpdate(requiredUpdateJSON) +// print("Required Update: \(requiredUpdate!)") +// } +// +// return LaunchGateConfiguration(alert: alert, optionalUpdate: optionalUpdate, requiredUpdate: requiredUpdate) +// } catch let error as DefaultParser.Error { +// print("LaunchGate — Error: \(error)") +// } catch let error as NSError { +// print("LaunchGate — Error: \(error.localizedDescription)") +// +// if let recoverySuggestion = error.localizedRecoverySuggestion { +// print(recoverySuggestion) +// } +// } +// +// return nil +// } // --- Experiments --- // private static func parseAlert(_ jsonData: Data) -> AlertConfiguration? { // do { @@ -111,25 +111,25 @@ class DefaultParser: LaunchGateParser { // } // } // --- End of Experiments --- - private static func parseAlert(_ json: JSON) throws -> AlertConfiguration? { - guard let message = json["message"] as? String else { throw Error.unableToParseAlert } - guard let blocking = json["blocking"] as? Bool else { throw Error.unableToParseAlert } - - return AlertConfiguration(message: message, blocking: blocking) - } - - private static func parseOptionalUpdate(_ json: JSON) throws -> UpdateConfiguration? { - guard let version = json["optionalVersion"] as? String else { throw Error.unableToParseOptionalUpdate } - guard let message = json["message"] as? String else { throw Error.unableToParseOptionalUpdate } - - return UpdateConfiguration(version: version, message: message) - } - - private static func parseRequiredUpdate(_ json: JSON) throws -> UpdateConfiguration? { - guard let version = json["minimumVersion"] as? String else { throw Error.unableToParseRequiredUpdate } - guard let message = json["message"] as? String else { throw Error.unableToParseRequiredUpdate } - - return UpdateConfiguration(version: version, message: message) - } +// private static func parseAlert(_ json: JSON) throws -> AlertConfiguration? { +// guard let message = json["message"] as? String else { throw Error.unableToParseAlert } +// guard let blocking = json["blocking"] as? Bool else { throw Error.unableToParseAlert } +// +// return AlertConfiguration(message: message, blocking: blocking) +// } +// +// private static func parseOptionalUpdate(_ json: JSON) throws -> UpdateConfiguration? { +// guard let version = json["optionalVersion"] as? String else { throw Error.unableToParseOptionalUpdate } +// guard let message = json["message"] as? String else { throw Error.unableToParseOptionalUpdate } +// +// return UpdateConfiguration(version: version, message: message) +// } +// +// private static func parseRequiredUpdate(_ json: JSON) throws -> UpdateConfiguration? { +// guard let version = json["minimumVersion"] as? String else { throw Error.unableToParseRequiredUpdate } +// guard let message = json["message"] as? String else { throw Error.unableToParseRequiredUpdate } +// +// return UpdateConfiguration(version: version, message: message) +// } } diff --git a/Source/LaunchGateConfiguration.swift b/Source/LaunchGateConfiguration.swift index 254a89f..7121648 100755 --- a/Source/LaunchGateConfiguration.swift +++ b/Source/LaunchGateConfiguration.swift @@ -20,25 +20,17 @@ public struct LaunchGateConfiguration: Decodable { /// A required `UpdateConfiguration`, parsed from the configuration file. var requiredUpdate: UpdateConfiguration? -// public init(from decoder: Decoder) throws { -// let iosContainer = try decoder.container(keyedBy: IOSRootKey.self) -// //let ios = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .ios) -// //self.alert = try iosContainer.decode(AlertConfiguration.self, forKey: .alert) -// //self.optionalUpdate = try iosContainer.decode(UpdateConfiguration.self, forKey: .optionalUpdate) -// //self.requiredUpdate = try iosContainer.decode(UpdateConfiguration.self, forKey: .requiredUpdate) -// //let alert = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .alert) -// //let optionalUpdate = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .optionalUpdate) -// //let requiredUpdate = try iosContainer.nestedContainer(keyedBy: IOSRootKey.self, forKey: .requiredUpdate) -// } -// enum IOSRootKey: String, CodingKey { -// case ios -// //case alert -// //case optionalUpdate -// //case requiredUpdate -// } -// enum ConfigCodingKeys: String, CodingKey { -// case alert -// case optionalUpdate -// case requiredUpdate -// } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: IOSCodingKeys.self) + let iosContainer = try container.nestedContainer(keyedBy: IOSCodingKeys.self, forKey: .ios) + alert = try iosContainer.decodeIfPresent(AlertConfiguration.self, forKey: .alert) + optionalUpdate = try iosContainer.decodeIfPresent(UpdateConfiguration.self, forKey: .optionalUpdate) + requiredUpdate = try iosContainer.decodeIfPresent(UpdateConfiguration.self, forKey: .requiredUpdate) + } + enum IOSCodingKeys: String, CodingKey { + case ios + case alert + case optionalUpdate + case requiredUpdate + } } diff --git a/Source/UpdateConfiguration.swift b/Source/UpdateConfiguration.swift index 7741cac..02bb0f9 100755 --- a/Source/UpdateConfiguration.swift +++ b/Source/UpdateConfiguration.swift @@ -20,12 +20,22 @@ public struct UpdateConfiguration: Decodable, Dialogable, Rememberable { self.message = message } public init(from decoder: Decoder) throws { - let optionalKeyedContainer = try? decoder.container(keyedBy: OptionalCodingKeys.self) - let requiredKeyedContainer = try? decoder.container(keyedBy: RequiredCodingKeys.self) - version = try optionalKeyedContainer!.decode(String.self, forKey: .version) - message = try optionalKeyedContainer!.decode(String.self, forKey: .message) - version = try requiredKeyedContainer!.decode(String.self, forKey: .version) - message = try requiredKeyedContainer!.decode(String.self, forKey: .message) + let optionalKeyedContainer = try decoder.container(keyedBy: OptionalCodingKeys.self) + let requiredKeyedContainer = try decoder.container(keyedBy: RequiredCodingKeys.self) + + do { + version = try optionalKeyedContainer.decode(String.self, forKey: .version) + message = try optionalKeyedContainer.decode(String.self, forKey: .message) + } catch { + do { + version = try requiredKeyedContainer.decode(String.self, forKey: .version) + message = try requiredKeyedContainer.decode(String.self, forKey: .message) + } catch { + throw error + } + + } + } enum OptionalCodingKeys: String, CodingKey { case version = "optionalVersion" From b01e6e7cb2d0a1b95a562263373c4a00333559b7 Mon Sep 17 00:00:00 2001 From: Britney Smith Date: Fri, 16 Nov 2018 08:59:44 -0500 Subject: [PATCH 24/25] Replaced parsing method with one that uses JSONDecoder; parsing works as expected --- Source/DefaultParser.swift | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Source/DefaultParser.swift b/Source/DefaultParser.swift index 5ce4170..08de804 100755 --- a/Source/DefaultParser.swift +++ b/Source/DefaultParser.swift @@ -30,16 +30,16 @@ class DefaultParser: LaunchGateParser { } } } -// func parse(_ jsonData: Data) -> LaunchGateConfiguration? { -// do { -// let decoder = JSONDecoder() -// let result = try decoder.decode(LaunchGateConfiguration.self, from: jsonData) -// return result -// } catch let error { -// print("LaunchGate — Error: \(error)") -// } -// return nil -// } + func parse(_ jsonData: Data) -> LaunchGateConfiguration? { + do { + let decoder = JSONDecoder() + let result = try decoder.decode(LaunchGateConfiguration.self, from: jsonData) + return result + } catch let error { + print("LaunchGate — Error: \(error)") + } + return nil + } // func parse(_ jsonData: Data) -> LaunchGateConfiguration? { // do { // print("Parsing...") From 3dae3dba2309e5b2b815c424e088e821abd8c92b Mon Sep 17 00:00:00 2001 From: Britney Smith Date: Fri, 16 Nov 2018 09:18:50 -0500 Subject: [PATCH 25/25] Cleanup - Removed unnecessary print statements, commented out code. Removed manual error handling (Decodable throws the appropriate errors) --- Source/DefaultParser.swift | 112 --------------------------- Source/DialogManager.swift | 3 +- Source/LaunchGate.swift | 1 - Source/LaunchGateConfiguration.swift | 2 +- Source/UpdateConfiguration.swift | 3 - 5 files changed, 2 insertions(+), 119 deletions(-) diff --git a/Source/DefaultParser.swift b/Source/DefaultParser.swift index 08de804..efccd9f 100755 --- a/Source/DefaultParser.swift +++ b/Source/DefaultParser.swift @@ -9,27 +9,7 @@ import Foundation class DefaultParser: LaunchGateParser { - typealias JSON = [String: AnyObject] - enum Error: LaunchGateError { - case unableToParseConfigurationObject - case unableToParseAlert - case unableToParseOptionalUpdate - case unableToParseRequiredUpdate - - var description: String { - switch self { - case .unableToParseConfigurationObject: - return "Unable to parse the configuration object (\"ios\") from JSON file." - case .unableToParseAlert: - return "Unable to parse the alert configuration from JSON file." - case .unableToParseOptionalUpdate: - return "Unable to parse the optional update configuration from JSON file." - case .unableToParseRequiredUpdate: - return "Unable to parse the required update configuration from JSON file." - } - } - } func parse(_ jsonData: Data) -> LaunchGateConfiguration? { do { let decoder = JSONDecoder() @@ -40,96 +20,4 @@ class DefaultParser: LaunchGateParser { } return nil } -// func parse(_ jsonData: Data) -> LaunchGateConfiguration? { -// do { -// print("Parsing...") -// let jsonData = try JSONSerialization.jsonObject(with: jsonData, options: []) -// guard let json = jsonData as? JSON else { throw Error.unableToParseConfigurationObject } -// guard let config = json["ios"] else { throw Error.unableToParseConfigurationObject } -// -// var alert: AlertConfiguration? -// var optionalUpdate: UpdateConfiguration? -// var requiredUpdate: UpdateConfiguration? -// -// if let alertJSON = config["alert"] as? JSON { -// alert = try DefaultParser.parseAlert(alertJSON) -// print("Alert: \(alert!)") -// } -// -// if let optionalUpdateJSON = config["optionalUpdate"] as? JSON { -// optionalUpdate = try DefaultParser.parseOptionalUpdate(optionalUpdateJSON) -// print("Optional Update: \(optionalUpdate!)") -// } -// -// if let requiredUpdateJSON = config["requiredUpdate"] as? JSON { -// requiredUpdate = try DefaultParser.parseRequiredUpdate(requiredUpdateJSON) -// print("Required Update: \(requiredUpdate!)") -// } -// -// return LaunchGateConfiguration(alert: alert, optionalUpdate: optionalUpdate, requiredUpdate: requiredUpdate) -// } catch let error as DefaultParser.Error { -// print("LaunchGate — Error: \(error)") -// } catch let error as NSError { -// print("LaunchGate — Error: \(error.localizedDescription)") -// -// if let recoverySuggestion = error.localizedRecoverySuggestion { -// print(recoverySuggestion) -// } -// } -// -// return nil -// } -// --- Experiments --- -// private static func parseAlert(_ jsonData: Data) -> AlertConfiguration? { -// do { -// let decoder = JSONDecoder() -// let result = try decoder.decode(AlertConfiguration.self, from: jsonData) -// return result -// } catch { -// print(error) -// return nil -// } -// } -// private static func parseOptionalUpdate(_ jsonData: Data) -> UpdateConfiguration? { -// do { -// let decoder = JSONDecoder() -// let result = try decoder.decode(UpdateConfiguration.self, from: jsonData) -// return result -// } catch { -// print(error) -// return nil -// } -// } -// private static func parseRequiredUpdate(_ jsonData: Data) -> UpdateConfiguration? { -// do { -// let decoder = JSONDecoder() -// let result = try decoder.decode(UpdateConfiguration.self, from: jsonData) -// return result -// } catch { -// print(error) -// return nil -// } -// } -// --- End of Experiments --- -// private static func parseAlert(_ json: JSON) throws -> AlertConfiguration? { -// guard let message = json["message"] as? String else { throw Error.unableToParseAlert } -// guard let blocking = json["blocking"] as? Bool else { throw Error.unableToParseAlert } -// -// return AlertConfiguration(message: message, blocking: blocking) -// } -// -// private static func parseOptionalUpdate(_ json: JSON) throws -> UpdateConfiguration? { -// guard let version = json["optionalVersion"] as? String else { throw Error.unableToParseOptionalUpdate } -// guard let message = json["message"] as? String else { throw Error.unableToParseOptionalUpdate } -// -// return UpdateConfiguration(version: version, message: message) -// } -// -// private static func parseRequiredUpdate(_ json: JSON) throws -> UpdateConfiguration? { -// guard let version = json["minimumVersion"] as? String else { throw Error.unableToParseRequiredUpdate } -// guard let message = json["message"] as? String else { throw Error.unableToParseRequiredUpdate } -// -// return UpdateConfiguration(version: version, message: message) -// } - } diff --git a/Source/DialogManager.swift b/Source/DialogManager.swift index 1b28820..048c7cc 100755 --- a/Source/DialogManager.swift +++ b/Source/DialogManager.swift @@ -40,8 +40,7 @@ class DialogManager { } func displayOptionalUpdateDialog(_ updateConfig: RememberableDialogSubject, updateURL: URL) { - let dialog = createAlertController(.optionalUpdate(updateURL: updateURL), message: updateConfig.message) - + let dialog = createAlertController(.optionalUpdate(updateURL: updateURL), message: updateConfig.message) displayAlertController(dialog) { () -> Void in Memory.remember(updateConfig) } diff --git a/Source/LaunchGate.swift b/Source/LaunchGate.swift index 132faa7..53e0950 100755 --- a/Source/LaunchGate.swift +++ b/Source/LaunchGate.swift @@ -65,7 +65,6 @@ public class LaunchGate { func performCheck(_ remoteFileManager: RemoteFileManager) { remoteFileManager.fetchRemoteFile { (jsonData) -> Void in if let config: LaunchGateConfiguration = self.parser.parse(jsonData) { - print("Config: \(config)") self.displayDialogIfNecessary(config, dialogManager: self.dialogManager) } } diff --git a/Source/LaunchGateConfiguration.swift b/Source/LaunchGateConfiguration.swift index 7121648..77c1ceb 100755 --- a/Source/LaunchGateConfiguration.swift +++ b/Source/LaunchGateConfiguration.swift @@ -19,7 +19,7 @@ public struct LaunchGateConfiguration: Decodable { /// A required `UpdateConfiguration`, parsed from the configuration file. var requiredUpdate: UpdateConfiguration? - + public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: IOSCodingKeys.self) let iosContainer = try container.nestedContainer(keyedBy: IOSCodingKeys.self, forKey: .ios) diff --git a/Source/UpdateConfiguration.swift b/Source/UpdateConfiguration.swift index 02bb0f9..5a59f27 100755 --- a/Source/UpdateConfiguration.swift +++ b/Source/UpdateConfiguration.swift @@ -22,7 +22,6 @@ public struct UpdateConfiguration: Decodable, Dialogable, Rememberable { public init(from decoder: Decoder) throws { let optionalKeyedContainer = try decoder.container(keyedBy: OptionalCodingKeys.self) let requiredKeyedContainer = try decoder.container(keyedBy: RequiredCodingKeys.self) - do { version = try optionalKeyedContainer.decode(String.self, forKey: .version) message = try optionalKeyedContainer.decode(String.self, forKey: .message) @@ -33,9 +32,7 @@ public struct UpdateConfiguration: Decodable, Dialogable, Rememberable { } catch { throw error } - } - } enum OptionalCodingKeys: String, CodingKey { case version = "optionalVersion"