From dae65285c9c7a12ae231ad3783b5c55bf0adcbc4 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 4 Dec 2019 13:24:13 -0500 Subject: [PATCH] remove unused --- MVMCore/MVMCore/Constants/JSON/JSON.swift | 10 -- .../MVMCore/Constants/JSON/JSONValue.swift | 122 ------------------ .../Models/ActionType/ActionModel.swift | 2 +- 3 files changed, 1 insertion(+), 133 deletions(-) delete mode 100644 MVMCore/MVMCore/Constants/JSON/JSON.swift delete mode 100644 MVMCore/MVMCore/Constants/JSON/JSONValue.swift diff --git a/MVMCore/MVMCore/Constants/JSON/JSON.swift b/MVMCore/MVMCore/Constants/JSON/JSON.swift deleted file mode 100644 index cf58455..0000000 --- a/MVMCore/MVMCore/Constants/JSON/JSON.swift +++ /dev/null @@ -1,10 +0,0 @@ -import Foundation - -public typealias JSONArray = [[String: Any]] -public typealias JSONObject = [String: Any] - -public enum JSONError: Error { - case pathNotFound - case data(path: String) - case other(error: Error) -} diff --git a/MVMCore/MVMCore/Constants/JSON/JSONValue.swift b/MVMCore/MVMCore/Constants/JSON/JSONValue.swift deleted file mode 100644 index 38f4e61..0000000 --- a/MVMCore/MVMCore/Constants/JSON/JSONValue.swift +++ /dev/null @@ -1,122 +0,0 @@ -import Foundation - -public typealias JSONValueArray = [[String: JSONValue]] -public typealias JSONValueObject = [String: JSONValue] - -public enum JSONValueError: Error { - case encode -} - -extension Optional { - func or(_ other: Optional) -> Optional { - switch self { - case .none: return other - case .some: return self - } - } - - func resolve(with error: @autoclosure () -> Error) throws -> Wrapped { - switch self { - case .none: throw error() - case .some(let wrapped): return wrapped - } - } -} - -public enum JSONValue: Codable, Equatable { - case string(String) - case int(Int) - case double(Double) - case bool(Bool) - case object([String: JSONValue]) - case array([JSONValue]) - case null - public init(from decoder: Decoder) throws { - let container = try decoder.singleValueContainer() - let value = ((try? container.decode(String.self)).map(JSONValue.string)) - .or((try? container.decode(Int.self)).map(JSONValue.int)) - .or((try? container.decode(Double.self)).map(JSONValue.double)) - .or((try? container.decode(Bool.self)).map(JSONValue.bool)) - .or((try? container.decode([String: JSONValue].self)).map(JSONValue.object)) - .or((try? container.decode([JSONValue].self)).map(JSONValue.array)) - - self = value ?? JSONValue.null - } - - func decode() throws -> T { - let encoded = try JSONEncoder().encode(self) - return try JSONDecoder().decode(T.self, from: encoded) - } - - public func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - switch self { - case .string(let string): try container.encode(string) - case .int(let int): try container.encode(int) - case .double(let double): try container.encode(double) - case .bool(let bool): try container.encode(bool) - case .object(let object): try container.encode(object) - case .array(let array): try container.encode(array) - case .null: break - } - } -} - -public func ==(lhs: JSONValue, rhs: JSONValue) -> Bool { - let ld = try? lhs.encode() - let rd = try? lhs.encode() - return ld == rd -} - -extension JSONValue: ExpressibleByStringLiteral { - public init(stringLiteral value: String) { - self = .string(value) - } -} - -extension JSONValue: ExpressibleByIntegerLiteral { - public init(integerLiteral value: Int) { - self = .int(value) - } -} - -extension JSONValue: ExpressibleByFloatLiteral { - public init(floatLiteral value: Double) { - self = .double(value) - } -} - -extension JSONValue: ExpressibleByBooleanLiteral { - public init(booleanLiteral value: Bool) { - self = .bool(value) - } -} - -extension JSONValue: ExpressibleByArrayLiteral { - public init(arrayLiteral elements: JSONValue...) { - self = .array(elements) - } -} - -extension JSONValue: ExpressibleByDictionaryLiteral { - public init(dictionaryLiteral elements: (String, JSONValue)...) { - self = .object([String: JSONValue](uniqueKeysWithValues: elements)) - } -} - -extension Dictionary where Key == String, Value == Any { - public func toJSONValue() throws -> [String: JSONValue] { - let data = try JSONSerialization.data(withJSONObject: self, options: .prettyPrinted) - return try JSONDecoder().decode([String:JSONValue].self, from: data) - } -} - -extension Dictionary where Key == String, Value == JSONValue { - public func toJSONObject() throws -> JSONObject { - let encoded = try JSONEncoder().encode(self) - guard let json = try JSONSerialization.jsonObject(with: encoded, options: .mutableContainers) as? JSONObject else { - throw JSONValueError.encode - } - return json - } -} diff --git a/MVMCore/MVMCore/Models/ActionType/ActionModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionModel.swift index d9980df..8b1158c 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionModel.swift @@ -11,7 +11,7 @@ import Foundation @objcMembers public class ActionModel: Codable { public var actionType: String? - public init(actionType: String?, pageType: String?) { + public init(actionType: String?) { self.actionType = actionType } }