From 16c7b61108beca746aa3f598a8419dcecb39d017 Mon Sep 17 00:00:00 2001 From: panxi Date: Tue, 12 Nov 2019 17:36:00 -0500 Subject: [PATCH 01/50] update with new code, move core code to mvmcore --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 68 +++++++++ .../Models/ActionType/ActionMapModel.swift | 19 +++ .../MVMCore/Models/Extensions/Decoder.swift | 55 ++++++++ .../MVMCore/Models/Extensions/Encoder.swift | 37 +++++ MVMCore/MVMCore/Models/JSON/JSONHelper.swift | 18 +++ MVMCore/MVMCore/Models/JSON/JSONValue.swift | 132 ++++++++++++++++++ MVMCore/MVMCore/Models/Model/Model.swift | 16 +++ .../MVMCore/Models/Model/ModelRegistry.swift | 97 +++++++++++++ 8 files changed, 442 insertions(+) create mode 100644 MVMCore/MVMCore/Models/ActionType/ActionMapModel.swift create mode 100644 MVMCore/MVMCore/Models/Extensions/Decoder.swift create mode 100644 MVMCore/MVMCore/Models/Extensions/Encoder.swift create mode 100644 MVMCore/MVMCore/Models/JSON/JSONHelper.swift create mode 100644 MVMCore/MVMCore/Models/JSON/JSONValue.swift create mode 100644 MVMCore/MVMCore/Models/Model/Model.swift create mode 100644 MVMCore/MVMCore/Models/Model/ModelRegistry.swift diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index dff3445..76072b0 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -39,6 +39,13 @@ 8876D5F31FB50AB000EB2E3D /* UIFont+MFSpacing.m in Sources */ = {isa = PBXBuildFile; fileRef = 8876D5E51FB50AB000EB2E3D /* UIFont+MFSpacing.m */; }; 8876D5F41FB50AB000EB2E3D /* UILabel+MFCustom.h in Headers */ = {isa = PBXBuildFile; fileRef = 8876D5E61FB50AB000EB2E3D /* UILabel+MFCustom.h */; settings = {ATTRIBUTES = (Public, ); }; }; 8876D5F51FB50AB000EB2E3D /* UILabel+MFCustom.m in Sources */ = {isa = PBXBuildFile; fileRef = 8876D5E71FB50AB000EB2E3D /* UILabel+MFCustom.m */; }; + 946EE1A3237B59C30036751F /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1A2237B59C30036751F /* Model.swift */; }; + 946EE1A7237B5B1C0036751F /* ModelRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1A6237B5B1C0036751F /* ModelRegistry.swift */; }; + 946EE1AB237B5C940036751F /* Decoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1AA237B5C940036751F /* Decoder.swift */; }; + 946EE1B0237B5EF70036751F /* JSONHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1AF237B5EF70036751F /* JSONHelper.swift */; }; + 946EE1B2237B5F260036751F /* JSONValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1B1237B5F260036751F /* JSONValue.swift */; }; + 946EE1B4237B619D0036751F /* Encoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1B3237B619D0036751F /* Encoder.swift */; }; + 946EE1BC237B691A0036751F /* ActionMapModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1BB237B691A0036751F /* ActionMapModel.swift */; }; A332F33F20C7231700DCD9D9 /* MVMCoreViewControllerAnimatedTransitioning.h in Headers */ = {isa = PBXBuildFile; fileRef = A332F33E20C7231600DCD9D9 /* MVMCoreViewControllerAnimatedTransitioning.h */; settings = {ATTRIBUTES = (Public, ); }; }; AF1201832108C9B400E2F592 /* MVMCoreViewManagerViewControllerProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = AF1201812108C9B400E2F592 /* MVMCoreViewManagerViewControllerProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; AF26DDAE1FCE6A37004E8F65 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = AF26DDB01FCE6A37004E8F65 /* Localizable.strings */; }; @@ -168,6 +175,13 @@ 8876D5E51FB50AB000EB2E3D /* UIFont+MFSpacing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIFont+MFSpacing.m"; sourceTree = ""; }; 8876D5E61FB50AB000EB2E3D /* UILabel+MFCustom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UILabel+MFCustom.h"; sourceTree = ""; }; 8876D5E71FB50AB000EB2E3D /* UILabel+MFCustom.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UILabel+MFCustom.m"; sourceTree = ""; }; + 946EE1A2237B59C30036751F /* Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = ""; }; + 946EE1A6237B5B1C0036751F /* ModelRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelRegistry.swift; sourceTree = ""; }; + 946EE1AA237B5C940036751F /* Decoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Decoder.swift; sourceTree = ""; }; + 946EE1AF237B5EF70036751F /* JSONHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONHelper.swift; sourceTree = ""; }; + 946EE1B1237B5F260036751F /* JSONValue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONValue.swift; sourceTree = ""; }; + 946EE1B3237B619D0036751F /* Encoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Encoder.swift; sourceTree = ""; }; + 946EE1BB237B691A0036751F /* ActionMapModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionMapModel.swift; sourceTree = ""; }; A332F33E20C7231600DCD9D9 /* MVMCoreViewControllerAnimatedTransitioning.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreViewControllerAnimatedTransitioning.h; sourceTree = ""; }; AF1201812108C9B400E2F592 /* MVMCoreViewManagerViewControllerProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreViewManagerViewControllerProtocol.h; sourceTree = ""; }; AF26DDAF1FCE6A37004E8F65 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = ""; }; @@ -310,6 +324,7 @@ 8876D5CB1FB50A9E00EB2E3D /* MVMCore */ = { isa = PBXGroup; children = ( + 946EE19B237B4DB80036751F /* Models */, AFBB96311FBA341E0008D868 /* Constants */, 8876D5D41FB50AAB00EB2E3D /* Utility */, AF43A7191FC5BE9E008E9347 /* MainProtocols */, @@ -363,6 +378,52 @@ path = Categories; sourceTree = ""; }; + 946EE19B237B4DB80036751F /* Models */ = { + isa = PBXGroup; + children = ( + 946EE1B6237B66630036751F /* ActionType */, + 946EE1A9237B5C720036751F /* Extensions */, + 946EE1A8237B5C650036751F /* Model */, + 946EE1AC237B5CB10036751F /* JSON */, + ); + path = Models; + sourceTree = ""; + }; + 946EE1A8237B5C650036751F /* Model */ = { + isa = PBXGroup; + children = ( + 946EE1A2237B59C30036751F /* Model.swift */, + 946EE1A6237B5B1C0036751F /* ModelRegistry.swift */, + ); + path = Model; + sourceTree = ""; + }; + 946EE1A9237B5C720036751F /* Extensions */ = { + isa = PBXGroup; + children = ( + 946EE1AA237B5C940036751F /* Decoder.swift */, + 946EE1B3237B619D0036751F /* Encoder.swift */, + ); + path = Extensions; + sourceTree = ""; + }; + 946EE1AC237B5CB10036751F /* JSON */ = { + isa = PBXGroup; + children = ( + 946EE1AF237B5EF70036751F /* JSONHelper.swift */, + 946EE1B1237B5F260036751F /* JSONValue.swift */, + ); + path = JSON; + sourceTree = ""; + }; + 946EE1B6237B66630036751F /* ActionType */ = { + isa = PBXGroup; + children = ( + 946EE1BB237B691A0036751F /* ActionMapModel.swift */, + ); + path = ActionType; + sourceTree = ""; + }; AF26DDAB1FCE5CF2004E8F65 /* Strings */ = { isa = PBXGroup; children = ( @@ -767,6 +828,7 @@ files = ( AFED77A71FCCA29400BAE689 /* MVMCoreViewControllerProgrammaticMappingObject.m in Sources */, AFBB96A01FBA3A9A0008D868 /* MVMCoreAlertOperation.m in Sources */, + 946EE1A7237B5B1C0036751F /* ModelRegistry.swift in Sources */, AFBB96641FBA3A570008D868 /* MVMCoreLoadHandler.m in Sources */, AFFCFA671FCCC0D700FD0730 /* MVMCoreLoadingOverlayHandler.m in Sources */, AFBB968E1FBA3A9A0008D868 /* MVMCoreNavigationHandler.m in Sources */, @@ -782,10 +844,14 @@ D282AAB62240085300C46919 /* MVMCoreGetterUtility+Extension.swift in Sources */, AFBB965F1FBA3A570008D868 /* MFFreebeeOperation.m in Sources */, AFBB96901FBA3A9A0008D868 /* MVMCoreNavigationObject.m in Sources */, + 946EE1AB237B5C940036751F /* Decoder.swift in Sources */, + 946EE1BC237B691A0036751F /* ActionMapModel.swift in Sources */, AFBB96A61FBA3A9A0008D868 /* MVMCoreTopAlertOperation.m in Sources */, 881D26931FCC9D180079C521 /* MVMCoreErrorObject.m in Sources */, + 946EE1B0237B5EF70036751F /* JSONHelper.swift in Sources */, 30349BF21FCCA78A00546A1E /* MVMCoreSessionTimeHandler.m in Sources */, 8876D5E91FB50AB000EB2E3D /* NSArray+MFConvenience.m in Sources */, + 946EE1B2237B5F260036751F /* JSONValue.swift in Sources */, AFBB96971FBA3A9A0008D868 /* MVMCorePresentViewControllerOperation.m in Sources */, AFBB96581FBA3A570008D868 /* FreeBeeAuthObject.m in Sources */, AF43A5781FBA5B7C008E9347 /* MVMCoreJSONConstants.m in Sources */, @@ -806,12 +872,14 @@ AF43A7071FC4D7A2008E9347 /* MVMCoreObject.m in Sources */, 01DF561421F90ADC00CC099B /* Dictionary+MFConvenience.swift in Sources */, AFBB96B11FBA3B590008D868 /* MVMCoreDispatchUtility.m in Sources */, + 946EE1A3237B59C30036751F /* Model.swift in Sources */, AFBB965B1FBA3A570008D868 /* FreeBeeUrlObject.m in Sources */, AFEA17A9209B6A1C00BC6740 /* MVMCoreBlockOperation.m in Sources */, AF43A70A1FC4F415008E9347 /* MVMCoreCache.m in Sources */, AF43A6FF1FBE3252008E9347 /* Reachability.m in Sources */, AFBB96921FBA3A9A0008D868 /* MVMCoreNavigationOperation.m in Sources */, AFBB96611FBA3A570008D868 /* MVMCoreLoadObject.m in Sources */, + 946EE1B4237B619D0036751F /* Encoder.swift in Sources */, AFBB96941FBA3A9A0008D868 /* MVMCorePresentAnimationOperation.m in Sources */, AF43A5841FBB66DE008E9347 /* MVMCoreConstants.m in Sources */, AFBB966A1FBA3A570008D868 /* MVMCoreLoadRequestOperation.m in Sources */, diff --git a/MVMCore/MVMCore/Models/ActionType/ActionMapModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionMapModel.swift new file mode 100644 index 0000000..055598c --- /dev/null +++ b/MVMCore/MVMCore/Models/ActionType/ActionMapModel.swift @@ -0,0 +1,19 @@ +// +// ActionMapModel.swift +// MVMCore +// +// Created by Suresh, Kamlesh on 10/3/19. +// Copyright © 2019 Suresh, Kamlesh. All rights reserved. +// + +import Foundation + +@objcMembers public class ActionMapModel: Codable { + public var actionType: String? + public var pageType: String? + + public init(actionType: String?, pageType: String?) { + self.actionType = actionType + self.pageType = pageType + } +} diff --git a/MVMCore/MVMCore/Models/Extensions/Decoder.swift b/MVMCore/MVMCore/Models/Extensions/Decoder.swift new file mode 100644 index 0000000..69a0aa8 --- /dev/null +++ b/MVMCore/MVMCore/Models/Extensions/Decoder.swift @@ -0,0 +1,55 @@ +// +// Decoder.swift +// MVMCore +// +// Created by Matt Brunce on 11/12/19. +// Copyright © 2019 myverizon. All rights reserved. +// + +import Foundation + +public protocol AnyDecoder { + func decode(_ type: T.Type, from data: Data) throws -> T +} + +extension JSONDecoder: AnyDecoder {} +extension PropertyListDecoder: AnyDecoder {} + +extension Data { + public func decode(using decoder: AnyDecoder = JSONDecoder()) throws -> T { + return try decoder.decode(T.self, from: self) + } +} + +extension KeyedDecodingContainerProtocol { + public func decode(forKey key: Key) throws -> T { + return try decode(T.self, forKey: key) + } + + public func decode( + forKey key: Key, + default defaultExpression: @autoclosure () -> T + ) throws -> T { + return try decodeIfPresent(T.self, forKey: key) ?? defaultExpression() + } +} + +extension Decodable { + public static func decode(fileName: String, bundle: Bundle = Bundle.main) throws -> Self { + guard let path = bundle.path(forResource: fileName, ofType: ".json") else { + throw JSONError.pathNotFound + } + + guard let jsonData = try? Data(contentsOf: URL(fileURLWithPath: path)) else { + throw JSONError.data(path: path) + } + + do { + return try jsonData.decode() + } catch { + throw JSONError.other(error: error) + } + } +} + + diff --git a/MVMCore/MVMCore/Models/Extensions/Encoder.swift b/MVMCore/MVMCore/Models/Extensions/Encoder.swift new file mode 100644 index 0000000..baee8ec --- /dev/null +++ b/MVMCore/MVMCore/Models/Extensions/Encoder.swift @@ -0,0 +1,37 @@ +// +// Encoder.swift +// MVMCore +// +// Created by Matt Brunce on 11/12/19. +// Copyright © 2019 myverizon. All rights reserved. +// + +import Foundation + +public protocol AnyEncoder { + func encode(_ value: T) throws -> Data +} + +extension JSONEncoder: AnyEncoder {} +extension PropertyListEncoder: AnyEncoder {} + +extension Encodable { + public func encode(using encoder: AnyEncoder = JSONEncoder()) throws -> Data { + return try encoder.encode(self) + } + + public func toJSON() -> JSONDictionary? { + guard let data = try? self.encode() else { return nil } + return (try? JSONSerialization.jsonObject(with: data, options: .allowFragments)).flatMap { $0 as? JSONDictionary } + } + + public func toJSONString() -> String? { + guard let json = self.toJSON(), + let data = try? JSONSerialization.data(withJSONObject: json, options: .prettyPrinted), + let string = String(data: data, encoding: .utf8) else{ + return nil + } + return string + } +} + diff --git a/MVMCore/MVMCore/Models/JSON/JSONHelper.swift b/MVMCore/MVMCore/Models/JSON/JSONHelper.swift new file mode 100644 index 0000000..eebb6ab --- /dev/null +++ b/MVMCore/MVMCore/Models/JSON/JSONHelper.swift @@ -0,0 +1,18 @@ +// +// JSONHelper.swift +// MVMCore +// +// Created by Matt Brunce on 11/12/19. +// Copyright © 2019 myverizon. All rights reserved. +// + +import Foundation + +public typealias JSONArray = [[String: Any]] +public typealias JSONDictionary = [String: Any] + +public enum JSONError: Error { + case pathNotFound + case data(path: String) + case other(error: Error) +} diff --git a/MVMCore/MVMCore/Models/JSON/JSONValue.swift b/MVMCore/MVMCore/Models/JSON/JSONValue.swift new file mode 100644 index 0000000..fcb50fd --- /dev/null +++ b/MVMCore/MVMCore/Models/JSON/JSONValue.swift @@ -0,0 +1,132 @@ +// +// JSONValue.swift +// MVMCore +// +// Created by Matt Brunce on 11/12/19. +// Copyright © 2019 myverizon. All rights reserved. +// + +import Foundation + +public typealias JSONValueArray = [[String: JSONValue]] +public typealias JSONValueDictionary = [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 -> JSONDictionary { + let encoded = try JSONEncoder().encode(self) + guard let json = try JSONSerialization.jsonObject(with: encoded, options: .mutableContainers) as? JSONDictionary else { + throw JSONValueError.encode + } + return json + } +} + + diff --git a/MVMCore/MVMCore/Models/Model/Model.swift b/MVMCore/MVMCore/Models/Model/Model.swift new file mode 100644 index 0000000..e2adaae --- /dev/null +++ b/MVMCore/MVMCore/Models/Model/Model.swift @@ -0,0 +1,16 @@ +// +// Model.swift +// MVMCore +// +// Created by Matt Brunce on 11/12/19. +// Copyright © 2019 myverizon. All rights reserved. +// + +import Foundation + +public protocol Model: Codable { + + static var identifier: String { get set } + +} + diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift new file mode 100644 index 0000000..76fc9e4 --- /dev/null +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -0,0 +1,97 @@ +// +// ModelRegistry.swift +// MVMCore +// +// Created by Matt Brunce on 11/12/19. +// Copyright © 2019 myverizon. All rights reserved. +// + +import Foundation + +public struct ModelRegistry { + public enum Error: Swift.Error { + case keyNotFound + case encoderError + case decoderError + case decoderErrorObjectNotPresent + case decoderErrorModelNotMapped + } + + fileprivate static var types = [String: Model.Type]() + + public static func register(_ type: M.Type) { + types[M.identifier] = type + } +} + + +extension KeyedDecodingContainer where Key : CodingKey{ + public enum TypeCodingKey: String, CodingKey { + //need to discuss this the enum + case moleculeName + case actionMap + } + + //MARK: - Decode + public func decode(codingKey: KeyedDecodingContainer.Key, typeCodingKey: TypeCodingKey) throws -> T { + guard let model: Model = try decodeIfPresent(codingKey: codingKey, typeCodingKey: typeCodingKey) else { + throw ModelRegistry.Error.decoderErrorObjectNotPresent + } + + guard let m = model as? T else { + throw ModelRegistry.Error.decoderError + } + + return m + } + + public func decode(codingKey: KeyedDecodingContainer.Key) throws -> ActionMapModel { + return try decode(codingKey: codingKey, typeCodingKey: .actionMap) + } + + //MARK: - DecodeIfPresent + public func decodeIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: TypeCodingKey) throws -> T? { + + //get the type string + let meta = try self.nestedContainer(keyedBy: TypeCodingKey.self, forKey: codingKey) + guard let type = try meta.decodeIfPresent(String.self, forKey: typeCodingKey) else { + return nil + } + + //get the type + guard let found = ModelRegistry.types[type] else { + throw ModelRegistry.Error.decoderErrorModelNotMapped + } + + //get the decoder for the propertyKey + let decoder = try self.superDecoder(forKey: codingKey) + + //decode the type using the decoder + let model = try found.init(from: decoder) + + guard let m = model as? T else { + throw ModelRegistry.Error.decoderError + } + return m + } + + public func decodeIfPresent(codingKey: KeyedDecodingContainer.Key) throws -> ActionMapModel? { + return try decodeIfPresent(codingKey: codingKey, typeCodingKey: .actionMap) + } +} + + +extension KeyedEncodingContainer where Key : CodingKey { + + public mutating func encodeIfPresent(_ value: Model?, forKey key: KeyedEncodingContainer.Key) throws { + if let v = value { + let encoder = self.superEncoder(forKey: key) + try v.encode(to: encoder) + } + } + + public mutating func encode(_ value: Model, forKey key: KeyedEncodingContainer.Key) throws { + let encoder = self.superEncoder(forKey: key) + try value.encode(to: encoder) + } +} From d38b521c66b631cb329c766f33168448bfc56bef Mon Sep 17 00:00:00 2001 From: panxi Date: Wed, 13 Nov 2019 18:02:40 -0500 Subject: [PATCH 02/50] Separate action and molecule name --- MVMCore/MVMCore/Models/Model/ModelRegistry.swift | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index 76fc9e4..1089d61 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -26,14 +26,13 @@ public struct ModelRegistry { extension KeyedDecodingContainer where Key : CodingKey{ - public enum TypeCodingKey: String, CodingKey { - //need to discuss this the enum - case moleculeName + + private enum TypeCodingKey: String, CodingKey { case actionMap } //MARK: - Decode - public func decode(codingKey: KeyedDecodingContainer.Key, typeCodingKey: TypeCodingKey) throws -> T { + public func decode(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> T { guard let model: Model = try decodeIfPresent(codingKey: codingKey, typeCodingKey: typeCodingKey) else { throw ModelRegistry.Error.decoderErrorObjectNotPresent } @@ -46,14 +45,14 @@ extension KeyedDecodingContainer where Key : CodingKey{ } public func decode(codingKey: KeyedDecodingContainer.Key) throws -> ActionMapModel { - return try decode(codingKey: codingKey, typeCodingKey: .actionMap) + return try decode(codingKey: codingKey, typeCodingKey: TypeCodingKey.actionMap) } //MARK: - DecodeIfPresent - public func decodeIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: TypeCodingKey) throws -> T? { + public func decodeIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> T? { //get the type string - let meta = try self.nestedContainer(keyedBy: TypeCodingKey.self, forKey: codingKey) + let meta = try self.nestedContainer(keyedBy: type(of: typeCodingKey), forKey: codingKey) guard let type = try meta.decodeIfPresent(String.self, forKey: typeCodingKey) else { return nil } @@ -76,7 +75,7 @@ extension KeyedDecodingContainer where Key : CodingKey{ } public func decodeIfPresent(codingKey: KeyedDecodingContainer.Key) throws -> ActionMapModel? { - return try decodeIfPresent(codingKey: codingKey, typeCodingKey: .actionMap) + return try decodeIfPresent(codingKey: codingKey, typeCodingKey: TypeCodingKey.actionMap) } } From 1b99abdb6e3e519455160ccd599a9f35d57ff03f Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Tue, 19 Nov 2019 15:37:53 -0500 Subject: [PATCH 03/50] fixes --- MVMCore/MVMCore/Models/Model/ModelRegistry.swift | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index 1089d61..05fbfa6 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -25,7 +25,7 @@ public struct ModelRegistry { } -extension KeyedDecodingContainer where Key : CodingKey{ +extension KeyedDecodingContainer where Key: CodingKey { private enum TypeCodingKey: String, CodingKey { case actionMap @@ -44,10 +44,6 @@ extension KeyedDecodingContainer where Key : CodingKey{ return m } - public func decode(codingKey: KeyedDecodingContainer.Key) throws -> ActionMapModel { - return try decode(codingKey: codingKey, typeCodingKey: TypeCodingKey.actionMap) - } - //MARK: - DecodeIfPresent public func decodeIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> T? { @@ -73,14 +69,10 @@ extension KeyedDecodingContainer where Key : CodingKey{ } return m } - - public func decodeIfPresent(codingKey: KeyedDecodingContainer.Key) throws -> ActionMapModel? { - return try decodeIfPresent(codingKey: codingKey, typeCodingKey: TypeCodingKey.actionMap) - } } -extension KeyedEncodingContainer where Key : CodingKey { +extension KeyedEncodingContainer where Key: CodingKey { public mutating func encodeIfPresent(_ value: Model?, forKey key: KeyedEncodingContainer.Key) throws { if let v = value { From 0d1c3196bf311a526df0bc90690a6f239ef00195 Mon Sep 17 00:00:00 2001 From: panxi Date: Fri, 22 Nov 2019 14:33:42 -0500 Subject: [PATCH 04/50] add unkeyedcontainer --- MVMCore/MVMCore/Models/Model/Model.swift | 2 +- .../MVMCore/Models/Model/ModelRegistry.swift | 23 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/MVMCore/MVMCore/Models/Model/Model.swift b/MVMCore/MVMCore/Models/Model/Model.swift index e2adaae..44e1025 100644 --- a/MVMCore/MVMCore/Models/Model/Model.swift +++ b/MVMCore/MVMCore/Models/Model/Model.swift @@ -10,7 +10,7 @@ import Foundation public protocol Model: Codable { - static var identifier: String { get set } + static var identifier: String { get } } diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index 05fbfa6..cd40a83 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -24,6 +24,27 @@ public struct ModelRegistry { } } +extension UnkeyedDecodingContainer { + + public mutating func decodeUnKeyedIfPresent(_ type: T.Type, typeCodingKey: C) throws -> T? where T : Decodable { + let meta = try self.nestedContainer(keyedBy: C.self) + guard let type = try meta.decodeIfPresent(String.self, forKey: typeCodingKey) else { + return nil + } + + //get the type + guard let found = ModelRegistry.types[type] else { + throw ModelRegistry.Error.decoderErrorModelNotMapped + } + let model = try self.decode(found) + + guard let m = model as? T else { + throw ModelRegistry.Error.decoderError + } + return m + } + +} extension KeyedDecodingContainer where Key: CodingKey { @@ -48,7 +69,7 @@ extension KeyedDecodingContainer where Key: CodingKey { public func decodeIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> T? { //get the type string - let meta = try self.nestedContainer(keyedBy: type(of: typeCodingKey), forKey: codingKey) + let meta = try self.nestedContainer(keyedBy: C.self, forKey: codingKey) guard let type = try meta.decodeIfPresent(String.self, forKey: typeCodingKey) else { return nil } From b2eb88f7f69a3c4242343ff4dc0de8df557f7ae6 Mon Sep 17 00:00:00 2001 From: panxi Date: Sun, 24 Nov 2019 23:14:25 -0500 Subject: [PATCH 05/50] update array decoding method --- MVMCore/MVMCore/Models/Model/Model.swift | 14 +++++ .../MVMCore/Models/Model/ModelRegistry.swift | 59 +++++++++++-------- 2 files changed, 47 insertions(+), 26 deletions(-) diff --git a/MVMCore/MVMCore/Models/Model/Model.swift b/MVMCore/MVMCore/Models/Model/Model.swift index 44e1025..8e37837 100644 --- a/MVMCore/MVMCore/Models/Model/Model.swift +++ b/MVMCore/MVMCore/Models/Model/Model.swift @@ -12,5 +12,19 @@ public protocol Model: Codable { static var identifier: String { get } + static func mvmdecode(keyedContainer: KeyedDecodingContainer, codingKey: K) throws -> Self? + static func mvmdecode(unkeyedContainer: inout UnkeyedDecodingContainer) throws -> Self? +} + +extension Model { + static public func mvmdecode(keyedContainer: KeyedDecodingContainer, codingKey: K) throws -> Self? { + let m = try keyedContainer.decodeIfPresent(self, forKey: codingKey) + return m + } + + static public func mvmdecode(unkeyedContainer: inout UnkeyedDecodingContainer) throws -> Self? { + let m = try unkeyedContainer.decodeIfPresent(self) + return m + } } diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index cd40a83..0b83a6f 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -24,28 +24,6 @@ public struct ModelRegistry { } } -extension UnkeyedDecodingContainer { - - public mutating func decodeUnKeyedIfPresent(_ type: T.Type, typeCodingKey: C) throws -> T? where T : Decodable { - let meta = try self.nestedContainer(keyedBy: C.self) - guard let type = try meta.decodeIfPresent(String.self, forKey: typeCodingKey) else { - return nil - } - - //get the type - guard let found = ModelRegistry.types[type] else { - throw ModelRegistry.Error.decoderErrorModelNotMapped - } - let model = try self.decode(found) - - guard let m = model as? T else { - throw ModelRegistry.Error.decoderError - } - return m - } - -} - extension KeyedDecodingContainer where Key: CodingKey { private enum TypeCodingKey: String, CodingKey { @@ -79,17 +57,46 @@ extension KeyedDecodingContainer where Key: CodingKey { throw ModelRegistry.Error.decoderErrorModelNotMapped } - //get the decoder for the propertyKey - let decoder = try self.superDecoder(forKey: codingKey) - //decode the type using the decoder - let model = try found.init(from: decoder) + let model = try found.mvmdecode(keyedContainer: self, codingKey: codingKey) guard let m = model as? T else { throw ModelRegistry.Error.decoderError } + return m } + + + public func decodeArrayIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> [Model]? { + + var unkeyedContainer = try nestedUnkeyedContainer(forKey: codingKey) + var otherUnkeyedContainer = try nestedUnkeyedContainer(forKey: codingKey) + var attributes = [Model.Type]() + while !unkeyedContainer.isAtEnd { + + let meta = try unkeyedContainer.nestedContainer(keyedBy: C.self) + guard let type = try meta.decodeIfPresent(String.self, forKey: typeCodingKey) else { + return nil + } + //get the type + guard let found = ModelRegistry.types[type] else { + throw ModelRegistry.Error.decoderErrorModelNotMapped + } + attributes.append(found) + } + + var i = 0 + var models = [Model]() + while !otherUnkeyedContainer.isAtEnd { + let foundModel = attributes[i] + if let model = try foundModel.mvmdecode(unkeyedContainer: &otherUnkeyedContainer) { + models.append(model) + } + i += 1 + } + return models.count > 0 ? models : nil + } } From a0dbc644c2d2444254b78a8c63800e7b62dc5674 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 25 Nov 2019 09:04:51 -0500 Subject: [PATCH 06/50] Line, and other corrections. merge --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 8 ++++---- .../{ActionMapModel.swift => ActionModel.swift} | 6 ++---- MVMCore/MVMCore/Models/Extensions/Encoder.swift | 2 +- MVMCore/MVMCore/Models/Model/Model.swift | 2 -- MVMCore/MVMCore/Models/Model/ModelRegistry.swift | 4 ---- 5 files changed, 7 insertions(+), 15 deletions(-) rename MVMCore/MVMCore/Models/ActionType/{ActionMapModel.swift => ActionModel.swift} (66%) diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index 76072b0..0e4cad7 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -45,7 +45,7 @@ 946EE1B0237B5EF70036751F /* JSONHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1AF237B5EF70036751F /* JSONHelper.swift */; }; 946EE1B2237B5F260036751F /* JSONValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1B1237B5F260036751F /* JSONValue.swift */; }; 946EE1B4237B619D0036751F /* Encoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1B3237B619D0036751F /* Encoder.swift */; }; - 946EE1BC237B691A0036751F /* ActionMapModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1BB237B691A0036751F /* ActionMapModel.swift */; }; + 946EE1BC237B691A0036751F /* ActionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1BB237B691A0036751F /* ActionModel.swift */; }; A332F33F20C7231700DCD9D9 /* MVMCoreViewControllerAnimatedTransitioning.h in Headers */ = {isa = PBXBuildFile; fileRef = A332F33E20C7231600DCD9D9 /* MVMCoreViewControllerAnimatedTransitioning.h */; settings = {ATTRIBUTES = (Public, ); }; }; AF1201832108C9B400E2F592 /* MVMCoreViewManagerViewControllerProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = AF1201812108C9B400E2F592 /* MVMCoreViewManagerViewControllerProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; AF26DDAE1FCE6A37004E8F65 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = AF26DDB01FCE6A37004E8F65 /* Localizable.strings */; }; @@ -181,7 +181,7 @@ 946EE1AF237B5EF70036751F /* JSONHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONHelper.swift; sourceTree = ""; }; 946EE1B1237B5F260036751F /* JSONValue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONValue.swift; sourceTree = ""; }; 946EE1B3237B619D0036751F /* Encoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Encoder.swift; sourceTree = ""; }; - 946EE1BB237B691A0036751F /* ActionMapModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionMapModel.swift; sourceTree = ""; }; + 946EE1BB237B691A0036751F /* ActionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionModel.swift; sourceTree = ""; }; A332F33E20C7231600DCD9D9 /* MVMCoreViewControllerAnimatedTransitioning.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreViewControllerAnimatedTransitioning.h; sourceTree = ""; }; AF1201812108C9B400E2F592 /* MVMCoreViewManagerViewControllerProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreViewManagerViewControllerProtocol.h; sourceTree = ""; }; AF26DDAF1FCE6A37004E8F65 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = ""; }; @@ -419,7 +419,7 @@ 946EE1B6237B66630036751F /* ActionType */ = { isa = PBXGroup; children = ( - 946EE1BB237B691A0036751F /* ActionMapModel.swift */, + 946EE1BB237B691A0036751F /* ActionModel.swift */, ); path = ActionType; sourceTree = ""; @@ -845,7 +845,7 @@ AFBB965F1FBA3A570008D868 /* MFFreebeeOperation.m in Sources */, AFBB96901FBA3A9A0008D868 /* MVMCoreNavigationObject.m in Sources */, 946EE1AB237B5C940036751F /* Decoder.swift in Sources */, - 946EE1BC237B691A0036751F /* ActionMapModel.swift in Sources */, + 946EE1BC237B691A0036751F /* ActionModel.swift in Sources */, AFBB96A61FBA3A9A0008D868 /* MVMCoreTopAlertOperation.m in Sources */, 881D26931FCC9D180079C521 /* MVMCoreErrorObject.m in Sources */, 946EE1B0237B5EF70036751F /* JSONHelper.swift in Sources */, diff --git a/MVMCore/MVMCore/Models/ActionType/ActionMapModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionModel.swift similarity index 66% rename from MVMCore/MVMCore/Models/ActionType/ActionMapModel.swift rename to MVMCore/MVMCore/Models/ActionType/ActionModel.swift index 055598c..d9980df 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionMapModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionModel.swift @@ -1,5 +1,5 @@ // -// ActionMapModel.swift +// ActionModel.swift // MVMCore // // Created by Suresh, Kamlesh on 10/3/19. @@ -8,12 +8,10 @@ import Foundation -@objcMembers public class ActionMapModel: Codable { +@objcMembers public class ActionModel: Codable { public var actionType: String? - public var pageType: String? public init(actionType: String?, pageType: String?) { self.actionType = actionType - self.pageType = pageType } } diff --git a/MVMCore/MVMCore/Models/Extensions/Encoder.swift b/MVMCore/MVMCore/Models/Extensions/Encoder.swift index baee8ec..db9c762 100644 --- a/MVMCore/MVMCore/Models/Extensions/Encoder.swift +++ b/MVMCore/MVMCore/Models/Extensions/Encoder.swift @@ -28,7 +28,7 @@ extension Encodable { public func toJSONString() -> String? { guard let json = self.toJSON(), let data = try? JSONSerialization.data(withJSONObject: json, options: .prettyPrinted), - let string = String(data: data, encoding: .utf8) else{ + let string = String(data: data, encoding: .utf8) else { return nil } return string diff --git a/MVMCore/MVMCore/Models/Model/Model.swift b/MVMCore/MVMCore/Models/Model/Model.swift index e2adaae..36d6403 100644 --- a/MVMCore/MVMCore/Models/Model/Model.swift +++ b/MVMCore/MVMCore/Models/Model/Model.swift @@ -9,8 +9,6 @@ import Foundation public protocol Model: Codable { - static var identifier: String { get set } - } diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index 05fbfa6..e5a83ef 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -26,10 +26,6 @@ public struct ModelRegistry { extension KeyedDecodingContainer where Key: CodingKey { - - private enum TypeCodingKey: String, CodingKey { - case actionMap - } //MARK: - Decode public func decode(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> T { From c412947d6f4405821aa0111d673a89c99bb5af5f Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 25 Nov 2019 09:05:17 -0500 Subject: [PATCH 07/50] small tweaks --- MVMCore/MVMCore/Constants/JSON/JSON.swift | 10 ++ .../MVMCore/Constants/JSON/JSONValue.swift | 122 ++++++++++++++++++ MVMCore/MVMCore/Models/Decoder.swift | 45 +++++++ MVMCore/MVMCore/Models/Encoder.swift | 27 ++++ MVMCore/MVMCore/Models/Holder.swift | 5 + MVMCore/MVMCore/Models/HolderManager.swift | 83 ++++++++++++ 6 files changed, 292 insertions(+) create mode 100644 MVMCore/MVMCore/Constants/JSON/JSON.swift create mode 100644 MVMCore/MVMCore/Constants/JSON/JSONValue.swift create mode 100644 MVMCore/MVMCore/Models/Decoder.swift create mode 100644 MVMCore/MVMCore/Models/Encoder.swift create mode 100644 MVMCore/MVMCore/Models/Holder.swift create mode 100644 MVMCore/MVMCore/Models/HolderManager.swift diff --git a/MVMCore/MVMCore/Constants/JSON/JSON.swift b/MVMCore/MVMCore/Constants/JSON/JSON.swift new file mode 100644 index 0000000..cf58455 --- /dev/null +++ b/MVMCore/MVMCore/Constants/JSON/JSON.swift @@ -0,0 +1,10 @@ +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 new file mode 100644 index 0000000..38f4e61 --- /dev/null +++ b/MVMCore/MVMCore/Constants/JSON/JSONValue.swift @@ -0,0 +1,122 @@ +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/Decoder.swift b/MVMCore/MVMCore/Models/Decoder.swift new file mode 100644 index 0000000..c04e494 --- /dev/null +++ b/MVMCore/MVMCore/Models/Decoder.swift @@ -0,0 +1,45 @@ +import Foundation + +public protocol AnyDecoder { + func decode(_ type: T.Type, from data: Data) throws -> T +} + +extension JSONDecoder: AnyDecoder {} +extension PropertyListDecoder: AnyDecoder {} + +extension Data { + public func decode(using decoder: AnyDecoder = JSONDecoder()) throws -> T { + return try decoder.decode(T.self, from: self) + } +} + +extension KeyedDecodingContainerProtocol { + public func decode(forKey key: Key) throws -> T { + return try decode(T.self, forKey: key) + } + + public func decode( + forKey key: Key, + default defaultExpression: @autoclosure () -> T + ) throws -> T { + return try decodeIfPresent(T.self, forKey: key) ?? defaultExpression() + } +} + +extension Decodable { + public static func decode(fileName: String, bundle: Bundle = Bundle.main) throws -> Self { + guard let path = bundle.path(forResource: fileName, ofType: ".json") else { + throw JSONError.pathNotFound + } + + guard let jsonData = try? Data(contentsOf: URL(fileURLWithPath: path)) else { + throw JSONError.data(path: path) + } + + do { + return try jsonData.decode() + } catch { + throw JSONError.other(error: error) + } + } +} diff --git a/MVMCore/MVMCore/Models/Encoder.swift b/MVMCore/MVMCore/Models/Encoder.swift new file mode 100644 index 0000000..0a236a5 --- /dev/null +++ b/MVMCore/MVMCore/Models/Encoder.swift @@ -0,0 +1,27 @@ +import Foundation + +public protocol AnyEncoder { + func encode(_ value: T) throws -> Data +} + +extension JSONEncoder: AnyEncoder {} +extension PropertyListEncoder: AnyEncoder {} + +extension Encodable { + public func encode(using encoder: AnyEncoder = JSONEncoder()) throws -> Data { + return try encoder.encode(self) + } + + public func toJSON() -> JSONObject? { + guard let data = try? encode() else { return nil } + return (try? JSONSerialization.jsonObject(with: data, options: .allowFragments)).flatMap { $0 as? JSONObject } + } + + public func toJSONString() -> String? { + guard let data = try? encode(), + let string = String(data: data, encoding: .utf8) else { + return nil + } + return string + } +} diff --git a/MVMCore/MVMCore/Models/Holder.swift b/MVMCore/MVMCore/Models/Holder.swift new file mode 100644 index 0000000..bee0637 --- /dev/null +++ b/MVMCore/MVMCore/Models/Holder.swift @@ -0,0 +1,5 @@ +import Foundation + +public protocol Holdable: Codable { + static var identifier: String { get set } +} diff --git a/MVMCore/MVMCore/Models/HolderManager.swift b/MVMCore/MVMCore/Models/HolderManager.swift new file mode 100644 index 0000000..8f28a7c --- /dev/null +++ b/MVMCore/MVMCore/Models/HolderManager.swift @@ -0,0 +1,83 @@ +import Foundation + +public struct HolderManager { + public enum Error: Swift.Error { + case codingKeyNotFound + case encoderError + case decoderError + case decoderErrorObjectNotPresent + case decoderErrorModelNotMapped + } + fileprivate static var types: [String: Holdable.Type] = [:] + public static func register(_ type: A.Type) { + types[A.identifier] = type + } +} + +extension KeyedDecodingContainer where Key : CodingKey { + public enum TypeCodingKey: String, CodingKey { + case actionType + } + + //MARK: - Decode + public func decode(codingKey: KeyedDecodingContainer.Key, typeCodingKey: TypeCodingKey) throws -> T { + guard let holdable: Holdable = try decodeIfPresent(codingKey: codingKey, typeCodingKey: typeCodingKey) else { + throw HolderManager.Error.decoderErrorObjectNotPresent + } + + guard let h = holdable as? T else { + throw HolderManager.Error.decoderError + } + return h + } + + public func decode(codingKey: KeyedDecodingContainer.Key) throws -> ActionTypeProtocol { + return try decode(codingKey: codingKey, typeCodingKey: .actionType) + } + + //MARK: - DecodeIfPresent + public func decodeIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: TypeCodingKey) throws -> T? { + + //get the type + let meta = try self.nestedContainer(keyedBy: TypeCodingKey.self, forKey: codingKey) + + guard let type = try meta.decodeIfPresent(String.self, forKey: typeCodingKey) else { + return nil + } + + //get the type + guard let found = HolderManager.types[type] else { + throw HolderManager.Error.decoderErrorModelNotMapped + } + + //get the decoder for the propertyKey + let decoder = try self.superDecoder(forKey: codingKey) + + //decode the type using the decoder + let holdable = try found.init(from: decoder) + + guard let h = holdable as? T else { + throw HolderManager.Error.decoderError + } + return h + } + + public func decodeIfPresent(codingKey: KeyedDecodingContainer.Key) throws -> ActionTypeProtocol? { + return try decodeIfPresent(codingKey: codingKey, typeCodingKey: .actionType) + } +} + +extension KeyedEncodingContainer where Key : CodingKey { + + public mutating func encodeIfPresent(_ value: Holdable?, forKey key: KeyedEncodingContainer.Key) throws { + if let v = value { + let encoder = self.superEncoder(forKey: key) + try v.encode(to: encoder) + } + } + + public mutating func encode(_ value: Holdable, forKey key: KeyedEncodingContainer.Key) throws { + let encoder = self.superEncoder(forKey: key) + try value.encode(to: encoder) + } +} From 72758675dcec4ddf7759756389950f70eca2c391 Mon Sep 17 00:00:00 2001 From: panxi Date: Mon, 2 Dec 2019 12:04:32 -0500 Subject: [PATCH 08/50] fix array decode if it's nil --- MVMCore/MVMCore/Models/Model/ModelRegistry.swift | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index b0246fe..a141ed4 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -65,13 +65,17 @@ extension KeyedDecodingContainer where Key: CodingKey { public func decodeArrayIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> [Model]? { - - var unkeyedContainer = try nestedUnkeyedContainer(forKey: codingKey) + var unkeyedContainer: UnkeyedDecodingContainer? + do { + unkeyedContainer = try nestedUnkeyedContainer(forKey: codingKey) + } catch { + return nil + } var otherUnkeyedContainer = try nestedUnkeyedContainer(forKey: codingKey) var attributes = [Model.Type]() - while !unkeyedContainer.isAtEnd { + while !unkeyedContainer!.isAtEnd { - let meta = try unkeyedContainer.nestedContainer(keyedBy: C.self) + let meta = try unkeyedContainer!.nestedContainer(keyedBy: C.self) guard let type = try meta.decodeIfPresent(String.self, forKey: typeCodingKey) else { return nil } From dae65285c9c7a12ae231ad3783b5c55bf0adcbc4 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 4 Dec 2019 13:24:13 -0500 Subject: [PATCH 09/50] 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 } } From 58af05319bfeff30df16b3f6023d9b60943f20c0 Mon Sep 17 00:00:00 2001 From: panxi Date: Wed, 4 Dec 2019 15:23:09 -0500 Subject: [PATCH 10/50] remove useless code --- MVMCore/MVMCore/Models/Decoder.swift | 45 ------------ MVMCore/MVMCore/Models/Encoder.swift | 27 ------- MVMCore/MVMCore/Models/Holder.swift | 5 -- MVMCore/MVMCore/Models/HolderManager.swift | 83 ---------------------- 4 files changed, 160 deletions(-) delete mode 100644 MVMCore/MVMCore/Models/Decoder.swift delete mode 100644 MVMCore/MVMCore/Models/Encoder.swift delete mode 100644 MVMCore/MVMCore/Models/Holder.swift delete mode 100644 MVMCore/MVMCore/Models/HolderManager.swift diff --git a/MVMCore/MVMCore/Models/Decoder.swift b/MVMCore/MVMCore/Models/Decoder.swift deleted file mode 100644 index c04e494..0000000 --- a/MVMCore/MVMCore/Models/Decoder.swift +++ /dev/null @@ -1,45 +0,0 @@ -import Foundation - -public protocol AnyDecoder { - func decode(_ type: T.Type, from data: Data) throws -> T -} - -extension JSONDecoder: AnyDecoder {} -extension PropertyListDecoder: AnyDecoder {} - -extension Data { - public func decode(using decoder: AnyDecoder = JSONDecoder()) throws -> T { - return try decoder.decode(T.self, from: self) - } -} - -extension KeyedDecodingContainerProtocol { - public func decode(forKey key: Key) throws -> T { - return try decode(T.self, forKey: key) - } - - public func decode( - forKey key: Key, - default defaultExpression: @autoclosure () -> T - ) throws -> T { - return try decodeIfPresent(T.self, forKey: key) ?? defaultExpression() - } -} - -extension Decodable { - public static func decode(fileName: String, bundle: Bundle = Bundle.main) throws -> Self { - guard let path = bundle.path(forResource: fileName, ofType: ".json") else { - throw JSONError.pathNotFound - } - - guard let jsonData = try? Data(contentsOf: URL(fileURLWithPath: path)) else { - throw JSONError.data(path: path) - } - - do { - return try jsonData.decode() - } catch { - throw JSONError.other(error: error) - } - } -} diff --git a/MVMCore/MVMCore/Models/Encoder.swift b/MVMCore/MVMCore/Models/Encoder.swift deleted file mode 100644 index 0a236a5..0000000 --- a/MVMCore/MVMCore/Models/Encoder.swift +++ /dev/null @@ -1,27 +0,0 @@ -import Foundation - -public protocol AnyEncoder { - func encode(_ value: T) throws -> Data -} - -extension JSONEncoder: AnyEncoder {} -extension PropertyListEncoder: AnyEncoder {} - -extension Encodable { - public func encode(using encoder: AnyEncoder = JSONEncoder()) throws -> Data { - return try encoder.encode(self) - } - - public func toJSON() -> JSONObject? { - guard let data = try? encode() else { return nil } - return (try? JSONSerialization.jsonObject(with: data, options: .allowFragments)).flatMap { $0 as? JSONObject } - } - - public func toJSONString() -> String? { - guard let data = try? encode(), - let string = String(data: data, encoding: .utf8) else { - return nil - } - return string - } -} diff --git a/MVMCore/MVMCore/Models/Holder.swift b/MVMCore/MVMCore/Models/Holder.swift deleted file mode 100644 index bee0637..0000000 --- a/MVMCore/MVMCore/Models/Holder.swift +++ /dev/null @@ -1,5 +0,0 @@ -import Foundation - -public protocol Holdable: Codable { - static var identifier: String { get set } -} diff --git a/MVMCore/MVMCore/Models/HolderManager.swift b/MVMCore/MVMCore/Models/HolderManager.swift deleted file mode 100644 index 8f28a7c..0000000 --- a/MVMCore/MVMCore/Models/HolderManager.swift +++ /dev/null @@ -1,83 +0,0 @@ -import Foundation - -public struct HolderManager { - public enum Error: Swift.Error { - case codingKeyNotFound - case encoderError - case decoderError - case decoderErrorObjectNotPresent - case decoderErrorModelNotMapped - } - fileprivate static var types: [String: Holdable.Type] = [:] - public static func register(_ type: A.Type) { - types[A.identifier] = type - } -} - -extension KeyedDecodingContainer where Key : CodingKey { - public enum TypeCodingKey: String, CodingKey { - case actionType - } - - //MARK: - Decode - public func decode(codingKey: KeyedDecodingContainer.Key, typeCodingKey: TypeCodingKey) throws -> T { - guard let holdable: Holdable = try decodeIfPresent(codingKey: codingKey, typeCodingKey: typeCodingKey) else { - throw HolderManager.Error.decoderErrorObjectNotPresent - } - - guard let h = holdable as? T else { - throw HolderManager.Error.decoderError - } - return h - } - - public func decode(codingKey: KeyedDecodingContainer.Key) throws -> ActionTypeProtocol { - return try decode(codingKey: codingKey, typeCodingKey: .actionType) - } - - //MARK: - DecodeIfPresent - public func decodeIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: TypeCodingKey) throws -> T? { - - //get the type - let meta = try self.nestedContainer(keyedBy: TypeCodingKey.self, forKey: codingKey) - - guard let type = try meta.decodeIfPresent(String.self, forKey: typeCodingKey) else { - return nil - } - - //get the type - guard let found = HolderManager.types[type] else { - throw HolderManager.Error.decoderErrorModelNotMapped - } - - //get the decoder for the propertyKey - let decoder = try self.superDecoder(forKey: codingKey) - - //decode the type using the decoder - let holdable = try found.init(from: decoder) - - guard let h = holdable as? T else { - throw HolderManager.Error.decoderError - } - return h - } - - public func decodeIfPresent(codingKey: KeyedDecodingContainer.Key) throws -> ActionTypeProtocol? { - return try decodeIfPresent(codingKey: codingKey, typeCodingKey: .actionType) - } -} - -extension KeyedEncodingContainer where Key : CodingKey { - - public mutating func encodeIfPresent(_ value: Holdable?, forKey key: KeyedEncodingContainer.Key) throws { - if let v = value { - let encoder = self.superEncoder(forKey: key) - try v.encode(to: encoder) - } - } - - public mutating func encode(_ value: Holdable, forKey key: KeyedEncodingContainer.Key) throws { - let encoder = self.superEncoder(forKey: key) - try value.encode(to: encoder) - } -} From 2105133c3855abf5ba50df1d6d7ca346d8d0f90a Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Fri, 6 Dec 2019 15:08:09 -0500 Subject: [PATCH 11/50] additions --- MVMCore/MVMCore/Models/Extensions/Decoder.swift | 9 +++++++++ MVMCore/MVMCore/Models/Model/ModelRegistry.swift | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/MVMCore/MVMCore/Models/Extensions/Decoder.swift b/MVMCore/MVMCore/Models/Extensions/Decoder.swift index 69a0aa8..5435b1d 100644 --- a/MVMCore/MVMCore/Models/Extensions/Decoder.swift +++ b/MVMCore/MVMCore/Models/Extensions/Decoder.swift @@ -35,6 +35,15 @@ extension KeyedDecodingContainerProtocol { } extension Decodable { + public static func decode(jsonDict: [String: Any]) throws -> Self { + let jsonData = try JSONSerialization.data(withJSONObject: jsonDict) + do { + return try jsonData.decode() + } catch { + throw JSONError.other(error: error) + } + } + public static func decode(fileName: String, bundle: Bundle = Bundle.main) throws -> Self { guard let path = bundle.path(forResource: fileName, ofType: ".json") else { throw JSONError.pathNotFound diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index a141ed4..719167d 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -22,6 +22,10 @@ public struct ModelRegistry { public static func register(_ type: M.Type) { types[M.identifier] = type } + + public static func getType(for name: String) -> Model.Type? { + return types[name] + } } extension KeyedDecodingContainer where Key: CodingKey { @@ -50,6 +54,7 @@ extension KeyedDecodingContainer where Key: CodingKey { //get the type guard let found = ModelRegistry.types[type] else { + MVMCoreLoggingHandler.logDebugMessage(withDelegate: "Model not mapped: \(type)") throw ModelRegistry.Error.decoderErrorModelNotMapped } From eb4e8fd8161b041d5500dbacdb810fe14b2c1486 Mon Sep 17 00:00:00 2001 From: panxi Date: Thu, 12 Dec 2019 17:28:02 -0500 Subject: [PATCH 12/50] add decode array method --- MVMCore/MVMCore/Models/Model/ModelRegistry.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index 719167d..36663f1 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -102,6 +102,13 @@ extension KeyedDecodingContainer where Key: CodingKey { } return models.count > 0 ? models : nil } + + public func decodeArray(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> [Model] { + guard let models: [Model] = try decodeArrayIfPresent(codingKey: codingKey, typeCodingKey: typeCodingKey) else { + throw ModelRegistry.Error.decoderErrorObjectNotPresent + } + return models + } } From 5fcbe414ec13f7f0a440be621a8d8abb5e03ca97 Mon Sep 17 00:00:00 2001 From: panxi Date: Fri, 13 Dec 2019 10:17:20 -0500 Subject: [PATCH 13/50] add encode method for model list --- MVMCore/MVMCore/Models/Model/ModelRegistry.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index 36663f1..f256e8d 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -125,4 +125,12 @@ extension KeyedEncodingContainer where Key: CodingKey { let encoder = self.superEncoder(forKey: key) try value.encode(to: encoder) } + + ///need instance type as input paramaeter list + public mutating func encodeArray(_ list:[T]?, forKey key:KeyedEncodingContainer.Key) throws { + var unkeyedContainer = self.nestedUnkeyedContainer(forKey: key) + try list?.forEach({ (model) in + try unkeyedContainer.encode(model) + }) + } } From a16c56505eb290754ef729a05ae305d43ba286c2 Mon Sep 17 00:00:00 2001 From: panxi Date: Fri, 13 Dec 2019 10:32:32 -0500 Subject: [PATCH 14/50] update encode method --- MVMCore/MVMCore/Models/Model/Model.swift | 14 ++++++++++++++ MVMCore/MVMCore/Models/Model/ModelRegistry.swift | 6 ++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/MVMCore/MVMCore/Models/Model/Model.swift b/MVMCore/MVMCore/Models/Model/Model.swift index 8e37837..0de3bdd 100644 --- a/MVMCore/MVMCore/Models/Model/Model.swift +++ b/MVMCore/MVMCore/Models/Model/Model.swift @@ -26,5 +26,19 @@ extension Model { let m = try unkeyedContainer.decodeIfPresent(self) return m } + + static public func mvmencode(keyedContainer: inout KeyedEncodingContainer, codingKey: K, model: Model) throws { + guard let typedModel = model as? Self else { + throw ModelRegistry.Error.encoderError + } + try keyedContainer.encode(typedModel, forKey: codingKey) + } + + static public func mvmencode(unkeyedContainer: inout UnkeyedEncodingContainer, model: Model) throws{ + guard let typedModel = model as? Self else { + throw ModelRegistry.Error.encoderError + } + try unkeyedContainer.encode(typedModel) + } } diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index f256e8d..5157d84 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -127,10 +127,12 @@ extension KeyedEncodingContainer where Key: CodingKey { } ///need instance type as input paramaeter list - public mutating func encodeArray(_ list:[T]?, forKey key:KeyedEncodingContainer.Key) throws { + public mutating func encodeArray(_ list:[Model]?, forKey key:KeyedEncodingContainer.Key) throws { var unkeyedContainer = self.nestedUnkeyedContainer(forKey: key) try list?.forEach({ (model) in - try unkeyedContainer.encode(model) + let typeString = type(of: model).identifier + let type = ModelRegistry.getType(for: typeString) + try type?.mvmencode(unkeyedContainer: &unkeyedContainer, model: model) }) } } From 3842858443977839544c9c62a046e8c60646cc96 Mon Sep 17 00:00:00 2001 From: panxi Date: Fri, 13 Dec 2019 11:00:23 -0500 Subject: [PATCH 15/50] add encodeArrayIfPresent --- MVMCore/MVMCore/Models/Model/ModelRegistry.swift | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index 5157d84..f097004 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -127,12 +127,17 @@ extension KeyedEncodingContainer where Key: CodingKey { } ///need instance type as input paramaeter list - public mutating func encodeArray(_ list:[Model]?, forKey key:KeyedEncodingContainer.Key) throws { + public mutating func encodeArray(_ list:[Model], forKey key:KeyedEncodingContainer.Key) throws { var unkeyedContainer = self.nestedUnkeyedContainer(forKey: key) - try list?.forEach({ (model) in + for model in list { let typeString = type(of: model).identifier let type = ModelRegistry.getType(for: typeString) try type?.mvmencode(unkeyedContainer: &unkeyedContainer, model: model) - }) + } + } + + public mutating func encodeArrayIfPresent(_ list:[Model]?, forKey key:KeyedEncodingContainer.Key) throws { + guard let models = list else { return } + try self.encodeArray(models, forKey: key) } } From d7a7425bb358d47cb726f55663e18479448216a2 Mon Sep 17 00:00:00 2001 From: panxi Date: Fri, 13 Dec 2019 11:04:32 -0500 Subject: [PATCH 16/50] decodeArray return empty array --- MVMCore/MVMCore/Models/Model/ModelRegistry.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index f097004..75436fc 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -105,7 +105,7 @@ extension KeyedDecodingContainer where Key: CodingKey { public func decodeArray(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> [Model] { guard let models: [Model] = try decodeArrayIfPresent(codingKey: codingKey, typeCodingKey: typeCodingKey) else { - throw ModelRegistry.Error.decoderErrorObjectNotPresent + return [Model]() } return models } From ffc71ae0e23de9803d45c0a3001d4d7582dccf5f Mon Sep 17 00:00:00 2001 From: panxi Date: Fri, 13 Dec 2019 13:41:25 -0500 Subject: [PATCH 17/50] update decodearray and encodearray method --- .../MVMCore/Models/Model/ModelRegistry.swift | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index 75436fc..1bf2a89 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -104,8 +104,31 @@ extension KeyedDecodingContainer where Key: CodingKey { } public func decodeArray(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> [Model] { - guard let models: [Model] = try decodeArrayIfPresent(codingKey: codingKey, typeCodingKey: typeCodingKey) else { - return [Model]() + var unkeyedContainer: UnkeyedDecodingContainer? + do { + unkeyedContainer = try nestedUnkeyedContainer(forKey: codingKey) + } catch { + throw ModelRegistry.Error.decoderErrorObjectNotPresent + } + var otherUnkeyedContainer = try nestedUnkeyedContainer(forKey: codingKey) + var attributes = [Model.Type]() + while !unkeyedContainer!.isAtEnd { + let meta = try unkeyedContainer!.nestedContainer(keyedBy: C.self) + let type = try meta.decode(String.self, forKey: typeCodingKey) + //get the type + guard let found = ModelRegistry.types[type] else { + throw ModelRegistry.Error.decoderErrorModelNotMapped + } + attributes.append(found) + } + var i = 0 + var models = [Model]() + while !otherUnkeyedContainer.isAtEnd { + let foundModel = attributes[i] + if let model = try foundModel.mvmdecode(unkeyedContainer: &otherUnkeyedContainer) { + models.append(model) + } + i += 1 } return models } @@ -138,6 +161,10 @@ extension KeyedEncodingContainer where Key: CodingKey { public mutating func encodeArrayIfPresent(_ list:[Model]?, forKey key:KeyedEncodingContainer.Key) throws { guard let models = list else { return } - try self.encodeArray(models, forKey: key) + do { + try self.encodeArray(models, forKey: key) + } catch { + return + } } } From 12e06894deed2efc85c7523af87cc1b5388449aa Mon Sep 17 00:00:00 2001 From: panxi Date: Fri, 13 Dec 2019 13:59:28 -0500 Subject: [PATCH 18/50] prevent nil --- .../MVMCore/Models/Model/ModelRegistry.swift | 27 ++----------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index 1bf2a89..3e3fc3d 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -100,36 +100,13 @@ extension KeyedDecodingContainer where Key: CodingKey { } i += 1 } - return models.count > 0 ? models : nil + return models } public func decodeArray(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> [Model] { - var unkeyedContainer: UnkeyedDecodingContainer? - do { - unkeyedContainer = try nestedUnkeyedContainer(forKey: codingKey) - } catch { + guard let models: [Model] = try decodeArrayIfPresent(codingKey: codingKey, typeCodingKey: typeCodingKey) else { throw ModelRegistry.Error.decoderErrorObjectNotPresent } - var otherUnkeyedContainer = try nestedUnkeyedContainer(forKey: codingKey) - var attributes = [Model.Type]() - while !unkeyedContainer!.isAtEnd { - let meta = try unkeyedContainer!.nestedContainer(keyedBy: C.self) - let type = try meta.decode(String.self, forKey: typeCodingKey) - //get the type - guard let found = ModelRegistry.types[type] else { - throw ModelRegistry.Error.decoderErrorModelNotMapped - } - attributes.append(found) - } - var i = 0 - var models = [Model]() - while !otherUnkeyedContainer.isAtEnd { - let foundModel = attributes[i] - if let model = try foundModel.mvmdecode(unkeyedContainer: &otherUnkeyedContainer) { - models.append(model) - } - i += 1 - } return models } } From 5d836fc7574231e3221ba2c279308d6255b80287 Mon Sep 17 00:00:00 2001 From: panxi Date: Fri, 13 Dec 2019 15:05:07 -0500 Subject: [PATCH 19/50] decodeIfPresent if nil --- MVMCore/MVMCore/Models/Model/ModelRegistry.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index 3e3fc3d..2a3ebb2 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -45,10 +45,14 @@ extension KeyedDecodingContainer where Key: CodingKey { //MARK: - DecodeIfPresent public func decodeIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> T? { - //get the type string - let meta = try self.nestedContainer(keyedBy: C.self, forKey: codingKey) - guard let type = try meta.decodeIfPresent(String.self, forKey: typeCodingKey) else { + var me: KeyedDecodingContainer? + do { + me = try self.nestedContainer(keyedBy: C.self, forKey: codingKey) + } catch { + return nil + } + guard let type = try me?.decodeIfPresent(String.self, forKey: typeCodingKey) else { return nil } From d75a152b9a35a85efa34fd3923753acb520e0bcd Mon Sep 17 00:00:00 2001 From: panxi Date: Fri, 13 Dec 2019 15:19:44 -0500 Subject: [PATCH 20/50] rename --- MVMCore/MVMCore/Models/Model/ModelRegistry.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index 2a3ebb2..df09507 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -46,13 +46,13 @@ extension KeyedDecodingContainer where Key: CodingKey { //MARK: - DecodeIfPresent public func decodeIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> T? { //get the type string - var me: KeyedDecodingContainer? + var meta: KeyedDecodingContainer? do { - me = try self.nestedContainer(keyedBy: C.self, forKey: codingKey) - } catch { + meta = try self.nestedContainer(keyedBy: C.self, forKey: codingKey) + }git catch { return nil } - guard let type = try me?.decodeIfPresent(String.self, forKey: typeCodingKey) else { + guard let type = try meta?.decodeIfPresent(String.self, forKey: typeCodingKey) else { return nil } From 4a05db9c9a0ea4de1bb3405ce6cc42c36f0c8ab4 Mon Sep 17 00:00:00 2001 From: panxi Date: Fri, 13 Dec 2019 15:20:11 -0500 Subject: [PATCH 21/50] fix typo --- MVMCore/MVMCore/Models/Model/ModelRegistry.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index df09507..75866fe 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -49,7 +49,7 @@ extension KeyedDecodingContainer where Key: CodingKey { var meta: KeyedDecodingContainer? do { meta = try self.nestedContainer(keyedBy: C.self, forKey: codingKey) - }git catch { + } catch { return nil } guard let type = try meta?.decodeIfPresent(String.self, forKey: typeCodingKey) else { From fc108373cba96fbe2b11b2e98d6380fd6bcef7c4 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 17 Dec 2019 14:12:07 -0500 Subject: [PATCH 22/50] Name changes and cleanup --- MVMCore/MVMCore/Models/Model/Model.swift | 28 ++--- .../MVMCore/Models/Model/ModelRegistry.swift | 109 ++++++++---------- 2 files changed, 65 insertions(+), 72 deletions(-) diff --git a/MVMCore/MVMCore/Models/Model/Model.swift b/MVMCore/MVMCore/Models/Model/Model.swift index 0de3bdd..544cb3a 100644 --- a/MVMCore/MVMCore/Models/Model/Model.swift +++ b/MVMCore/MVMCore/Models/Model/Model.swift @@ -12,33 +12,33 @@ public protocol Model: Codable { static var identifier: String { get } - static func mvmdecode(keyedContainer: KeyedDecodingContainer, codingKey: K) throws -> Self? - static func mvmdecode(unkeyedContainer: inout UnkeyedDecodingContainer) throws -> Self? + /// Convenience function to decode to model using a keyed container. + static func decode(keyedContainer: KeyedDecodingContainer, codingKey: K) throws -> Self? + /// Convenience function to decode to model using an unkeyed container. + static func decode(unkeyedContainer: inout UnkeyedDecodingContainer) throws -> Self? + /// Convenience function to encode model using a keyed container. + func encode(keyedContainer: inout KeyedEncodingContainer, codingKey: K) throws + /// Convenience function to encode model using an unkeyed container. + func encode(unkeyedContainer: inout UnkeyedEncodingContainer) throws } extension Model { - static public func mvmdecode(keyedContainer: KeyedDecodingContainer, codingKey: K) throws -> Self? { + static public func decode(keyedContainer: KeyedDecodingContainer, codingKey: K) throws -> Self? { let m = try keyedContainer.decodeIfPresent(self, forKey: codingKey) return m } - static public func mvmdecode(unkeyedContainer: inout UnkeyedDecodingContainer) throws -> Self? { + static public func decode(unkeyedContainer: inout UnkeyedDecodingContainer) throws -> Self? { let m = try unkeyedContainer.decodeIfPresent(self) return m } - static public func mvmencode(keyedContainer: inout KeyedEncodingContainer, codingKey: K, model: Model) throws { - guard let typedModel = model as? Self else { - throw ModelRegistry.Error.encoderError - } - try keyedContainer.encode(typedModel, forKey: codingKey) + public func encode(keyedContainer: inout KeyedEncodingContainer, codingKey: K) throws { + try keyedContainer.encode(self, forKey: codingKey) } - static public func mvmencode(unkeyedContainer: inout UnkeyedEncodingContainer, model: Model) throws{ - guard let typedModel = model as? Self else { - throw ModelRegistry.Error.encoderError - } - try unkeyedContainer.encode(typedModel) + public func encode(unkeyedContainer: inout UnkeyedEncodingContainer) throws{ + try unkeyedContainer.encode(self) } } diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index 75866fe..b811646 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -19,6 +19,7 @@ public struct ModelRegistry { fileprivate static var types = [String: Model.Type]() + /// Register the model. public static func register(_ type: M.Type) { types[M.identifier] = type } @@ -31,8 +32,9 @@ public struct ModelRegistry { extension KeyedDecodingContainer where Key: CodingKey { //MARK: - Decode - public func decode(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> T { - guard let model: Model = try decodeIfPresent(codingKey: codingKey, typeCodingKey: typeCodingKey) else { + /// Decodes to a registered model based on the identifier + public func decodeModel(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> T { + guard let model: Model = try decodeModelIfPresent(codingKey: codingKey, typeCodingKey: typeCodingKey) else { throw ModelRegistry.Error.decoderErrorObjectNotPresent } @@ -44,26 +46,27 @@ extension KeyedDecodingContainer where Key: CodingKey { } //MARK: - DecodeIfPresent - public func decodeIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> T? { - //get the type string - var meta: KeyedDecodingContainer? + /// Decodes to a registered model based on the identifier, optional. + public func decodeModelIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> T? { + //get the identifier string + var container: KeyedDecodingContainer? do { - meta = try self.nestedContainer(keyedBy: C.self, forKey: codingKey) + container = try nestedContainer(keyedBy: C.self, forKey: codingKey) } catch { return nil } - guard let type = try meta?.decodeIfPresent(String.self, forKey: typeCodingKey) else { + guard let identifier = try container?.decodeIfPresent(String.self, forKey: typeCodingKey) else { return nil } //get the type - guard let found = ModelRegistry.types[type] else { - MVMCoreLoggingHandler.logDebugMessage(withDelegate: "Model not mapped: \(type)") + guard let type = ModelRegistry.types[identifier] else { + MVMCoreLoggingHandler.logDebugMessage(withDelegate: "Model not mapped: \(identifier)") throw ModelRegistry.Error.decoderErrorModelNotMapped } //decode the type using the decoder - let model = try found.mvmdecode(keyedContainer: self, codingKey: codingKey) + let model = try type.decode(keyedContainer: self, codingKey: codingKey) guard let m = model as? T else { throw ModelRegistry.Error.decoderError @@ -72,80 +75,70 @@ extension KeyedDecodingContainer where Key: CodingKey { return m } - - public func decodeArrayIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> [Model]? { - var unkeyedContainer: UnkeyedDecodingContainer? - do { - unkeyedContainer = try nestedUnkeyedContainer(forKey: codingKey) - } catch { - return nil - } - var otherUnkeyedContainer = try nestedUnkeyedContainer(forKey: codingKey) - var attributes = [Model.Type]() - while !unkeyedContainer!.isAtEnd { - - let meta = try unkeyedContainer!.nestedContainer(keyedBy: C.self) - guard let type = try meta.decodeIfPresent(String.self, forKey: typeCodingKey) else { - return nil - } - //get the type - guard let found = ModelRegistry.types[type] else { - throw ModelRegistry.Error.decoderErrorModelNotMapped - } - attributes.append(found) - } + /// Decodes an array of registered model based on the identifiers, optional. + public func decodeModelsIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> [Model]? { + var models = [Model]() + var container = try nestedUnkeyedContainer(forKey: codingKey) + var containerCopy = container var i = 0 - var models = [Model]() - while !otherUnkeyedContainer.isAtEnd { - let foundModel = attributes[i] - if let model = try foundModel.mvmdecode(unkeyedContainer: &otherUnkeyedContainer) { - models.append(model) + let count = container.count ?? 0 + + while !container.isAtEnd { + if i < count { + let nestedContainer = try container.nestedContainer(keyedBy: C.self) + if let identifier = try nestedContainer.decodeIfPresent(String.self, forKey: typeCodingKey) { + //get the type + guard let type = ModelRegistry.types[identifier] else { + throw ModelRegistry.Error.decoderErrorModelNotMapped + } + //now get the decoder to use for the type + let decoder = try containerCopy.superDecoder() + let model = try type.init(from: decoder) + models.append(model) + } + i+=1 } - i += 1 } - return models + return models.count > 0 ? models : nil } - public func decodeArray(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> [Model] { - guard let models: [Model] = try decodeArrayIfPresent(codingKey: codingKey, typeCodingKey: typeCodingKey) else { + /// Decodes an array of registered model based on the identifiers. + public func decodeModels(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> [Model] { + guard let models: [Model] = try decodeModelsIfPresent(codingKey: codingKey, typeCodingKey: typeCodingKey) else { throw ModelRegistry.Error.decoderErrorObjectNotPresent } return models } } - extension KeyedEncodingContainer where Key: CodingKey { - public mutating func encodeIfPresent(_ value: Model?, forKey key: KeyedEncodingContainer.Key) throws { + /// Encodes a model, optional. + public mutating func encodeModelIfPresent(_ value: Model?, forKey key: KeyedEncodingContainer.Key) throws { if let v = value { let encoder = self.superEncoder(forKey: key) try v.encode(to: encoder) } } - public mutating func encode(_ value: Model, forKey key: KeyedEncodingContainer.Key) throws { + /// Encodes a model. + public mutating func encodeModel(_ value: Model, forKey key: KeyedEncodingContainer.Key) throws { let encoder = self.superEncoder(forKey: key) try value.encode(to: encoder) } - ///need instance type as input paramaeter list - public mutating func encodeArray(_ list:[Model], forKey key:KeyedEncodingContainer.Key) throws { - var unkeyedContainer = self.nestedUnkeyedContainer(forKey: key) - for model in list { - let typeString = type(of: model).identifier - let type = ModelRegistry.getType(for: typeString) - try type?.mvmencode(unkeyedContainer: &unkeyedContainer, model: model) - } + /// Encodes an array of models + public mutating func encodeModels(_ list: [Model], forKey key:KeyedEncodingContainer.Key) throws { + try encodeModelsIfPresent(list, forKey: key) } - public mutating func encodeArrayIfPresent(_ list:[Model]?, forKey key:KeyedEncodingContainer.Key) throws { - guard let models = list else { return } - do { - try self.encodeArray(models, forKey: key) - } catch { - return + /// Encodes an array of models, optional, need instance type as input paramaeter list + public mutating func encodeModelsIfPresent(_ list: [Model]?, forKey key:KeyedEncodingContainer.Key) throws { + guard let list = list else { return } + var unkeyedContainer = self.nestedUnkeyedContainer(forKey: key) + for model in list { + try model.encode(unkeyedContainer: &unkeyedContainer) } } } From 5f395f8cc37138120504fb6381e34fb8df0f115b Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 18 Dec 2019 12:09:22 -0500 Subject: [PATCH 23/50] fixes --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 40 +++++++++++++++++-- .../Models/ActionType/ActionCall.swift | 17 ++++++++ .../Models/ActionType/ActionModel.swift | 17 -------- .../Models/ActionType/ActionOpenApp.swift | 17 ++++++++ .../Models/ActionType/ActionOpenPage.swift | 17 ++++++++ .../Models/ActionType/ActionOpenUrl.swift | 17 ++++++++ .../Models/ActionType/ActionPopup.swift | 17 ++++++++ .../Models/ActionType/ActionProtocol.swift | 23 +++++++++++ .../Models/ActionType/ActionTopAlert.swift | 17 ++++++++ .../KeyedDecodingContainer+CodingKey.swift | 34 ++++++++++++++++ .../MVMCore/Models/Model/ModelRegistry.swift | 38 +++++++++--------- MVMCore/MVMCore/Models/ModelMapping.swift | 20 ++++++++++ .../MVMCore/Session/MVMCoreSessionObject.m | 2 + 13 files changed, 237 insertions(+), 39 deletions(-) create mode 100644 MVMCore/MVMCore/Models/ActionType/ActionCall.swift delete mode 100644 MVMCore/MVMCore/Models/ActionType/ActionModel.swift create mode 100644 MVMCore/MVMCore/Models/ActionType/ActionOpenApp.swift create mode 100644 MVMCore/MVMCore/Models/ActionType/ActionOpenPage.swift create mode 100644 MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift create mode 100644 MVMCore/MVMCore/Models/ActionType/ActionPopup.swift create mode 100644 MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift create mode 100644 MVMCore/MVMCore/Models/ActionType/ActionTopAlert.swift create mode 100644 MVMCore/MVMCore/Models/Extensions/KeyedDecodingContainer+CodingKey.swift create mode 100644 MVMCore/MVMCore/Models/ModelMapping.swift diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index 0e4cad7..34c05a6 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -22,6 +22,14 @@ /* Begin PBXBuildFile section */ 01DF561421F90ADC00CC099B /* Dictionary+MFConvenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF561321F90ADC00CC099B /* Dictionary+MFConvenience.swift */; }; + 01F2A03623A80A7300D954D8 /* ActionProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A03523A80A7300D954D8 /* ActionProtocol.swift */; }; + 01F2A03923A812DD00D954D8 /* ActionOpenUrl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A03823A812DD00D954D8 /* ActionOpenUrl.swift */; }; + 01F2A03B23A8159900D954D8 /* ActionOpenApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A03A23A8159900D954D8 /* ActionOpenApp.swift */; }; + 01F2A04C23A82B1B00D954D8 /* ActionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A04B23A82B1B00D954D8 /* ActionCall.swift */; }; + 01F2A04E23A82CF500D954D8 /* ActionPopup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A04D23A82CF500D954D8 /* ActionPopup.swift */; }; + 01F2A05023A82D0800D954D8 /* ActionTopAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A04F23A82D0800D954D8 /* ActionTopAlert.swift */; }; + 01F2A05223A8325100D954D8 /* ModelMapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A05123A8325100D954D8 /* ModelMapping.swift */; }; + 01F2A05423A83E9200D954D8 /* KeyedDecodingContainer+CodingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A05323A83E9200D954D8 /* KeyedDecodingContainer+CodingKey.swift */; }; 30349BF11FCCA78A00546A1E /* MVMCoreSessionTimeHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 30349BEF1FCCA78A00546A1E /* MVMCoreSessionTimeHandler.h */; settings = {ATTRIBUTES = (Public, ); }; }; 30349BF21FCCA78A00546A1E /* MVMCoreSessionTimeHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 30349BF01FCCA78A00546A1E /* MVMCoreSessionTimeHandler.m */; }; 881D26931FCC9D180079C521 /* MVMCoreErrorObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 881D268F1FCC9D180079C521 /* MVMCoreErrorObject.m */; }; @@ -45,7 +53,7 @@ 946EE1B0237B5EF70036751F /* JSONHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1AF237B5EF70036751F /* JSONHelper.swift */; }; 946EE1B2237B5F260036751F /* JSONValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1B1237B5F260036751F /* JSONValue.swift */; }; 946EE1B4237B619D0036751F /* Encoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1B3237B619D0036751F /* Encoder.swift */; }; - 946EE1BC237B691A0036751F /* ActionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1BB237B691A0036751F /* ActionModel.swift */; }; + 946EE1BC237B691A0036751F /* ActionOpenPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1BB237B691A0036751F /* ActionOpenPage.swift */; }; A332F33F20C7231700DCD9D9 /* MVMCoreViewControllerAnimatedTransitioning.h in Headers */ = {isa = PBXBuildFile; fileRef = A332F33E20C7231600DCD9D9 /* MVMCoreViewControllerAnimatedTransitioning.h */; settings = {ATTRIBUTES = (Public, ); }; }; AF1201832108C9B400E2F592 /* MVMCoreViewManagerViewControllerProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = AF1201812108C9B400E2F592 /* MVMCoreViewManagerViewControllerProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; AF26DDAE1FCE6A37004E8F65 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = AF26DDB01FCE6A37004E8F65 /* Localizable.strings */; }; @@ -154,6 +162,14 @@ /* Begin PBXFileReference section */ 01DF561321F90ADC00CC099B /* Dictionary+MFConvenience.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Dictionary+MFConvenience.swift"; sourceTree = ""; }; + 01F2A03523A80A7300D954D8 /* ActionProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionProtocol.swift; sourceTree = ""; }; + 01F2A03823A812DD00D954D8 /* ActionOpenUrl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionOpenUrl.swift; sourceTree = ""; }; + 01F2A03A23A8159900D954D8 /* ActionOpenApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionOpenApp.swift; sourceTree = ""; }; + 01F2A04B23A82B1B00D954D8 /* ActionCall.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionCall.swift; sourceTree = ""; }; + 01F2A04D23A82CF500D954D8 /* ActionPopup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionPopup.swift; sourceTree = ""; }; + 01F2A04F23A82D0800D954D8 /* ActionTopAlert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionTopAlert.swift; sourceTree = ""; }; + 01F2A05123A8325100D954D8 /* ModelMapping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelMapping.swift; sourceTree = ""; }; + 01F2A05323A83E9200D954D8 /* KeyedDecodingContainer+CodingKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "KeyedDecodingContainer+CodingKey.swift"; sourceTree = ""; }; 0A11030B20864F94008ADD90 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Localizable.strings; sourceTree = ""; }; 0A11030C20864F9A008ADD90 /* es-MX */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "es-MX"; path = "es-MX.lproj/Localizable.strings"; sourceTree = ""; }; 30349BEF1FCCA78A00546A1E /* MVMCoreSessionTimeHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreSessionTimeHandler.h; sourceTree = ""; }; @@ -181,7 +197,7 @@ 946EE1AF237B5EF70036751F /* JSONHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONHelper.swift; sourceTree = ""; }; 946EE1B1237B5F260036751F /* JSONValue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONValue.swift; sourceTree = ""; }; 946EE1B3237B619D0036751F /* Encoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Encoder.swift; sourceTree = ""; }; - 946EE1BB237B691A0036751F /* ActionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionModel.swift; sourceTree = ""; }; + 946EE1BB237B691A0036751F /* ActionOpenPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionOpenPage.swift; sourceTree = ""; }; A332F33E20C7231600DCD9D9 /* MVMCoreViewControllerAnimatedTransitioning.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreViewControllerAnimatedTransitioning.h; sourceTree = ""; }; AF1201812108C9B400E2F592 /* MVMCoreViewManagerViewControllerProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreViewManagerViewControllerProtocol.h; sourceTree = ""; }; AF26DDAF1FCE6A37004E8F65 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = ""; }; @@ -381,6 +397,7 @@ 946EE19B237B4DB80036751F /* Models */ = { isa = PBXGroup; children = ( + 01F2A05123A8325100D954D8 /* ModelMapping.swift */, 946EE1B6237B66630036751F /* ActionType */, 946EE1A9237B5C720036751F /* Extensions */, 946EE1A8237B5C650036751F /* Model */, @@ -403,6 +420,7 @@ children = ( 946EE1AA237B5C940036751F /* Decoder.swift */, 946EE1B3237B619D0036751F /* Encoder.swift */, + 01F2A05323A83E9200D954D8 /* KeyedDecodingContainer+CodingKey.swift */, ); path = Extensions; sourceTree = ""; @@ -419,7 +437,13 @@ 946EE1B6237B66630036751F /* ActionType */ = { isa = PBXGroup; children = ( - 946EE1BB237B691A0036751F /* ActionModel.swift */, + 01F2A03523A80A7300D954D8 /* ActionProtocol.swift */, + 946EE1BB237B691A0036751F /* ActionOpenPage.swift */, + 01F2A03823A812DD00D954D8 /* ActionOpenUrl.swift */, + 01F2A03A23A8159900D954D8 /* ActionOpenApp.swift */, + 01F2A04B23A82B1B00D954D8 /* ActionCall.swift */, + 01F2A04D23A82CF500D954D8 /* ActionPopup.swift */, + 01F2A04F23A82D0800D954D8 /* ActionTopAlert.swift */, ); path = ActionType; sourceTree = ""; @@ -833,9 +857,11 @@ AFFCFA671FCCC0D700FD0730 /* MVMCoreLoadingOverlayHandler.m in Sources */, AFBB968E1FBA3A9A0008D868 /* MVMCoreNavigationHandler.m in Sources */, D2E1FAD92260C3E400AEFD8C /* DelegateObject.swift in Sources */, + 01F2A03623A80A7300D954D8 /* ActionProtocol.swift in Sources */, AFBB96991FBA3A9A0008D868 /* MVMCoreAlertController.m in Sources */, 881D26941FCC9D180079C521 /* MVMCoreOperation.m in Sources */, AFED77A41FCCA29400BAE689 /* MVMCoreViewControllerMappingObject.m in Sources */, + 01F2A04C23A82B1B00D954D8 /* ActionCall.swift in Sources */, 8876D5ED1FB50AB000EB2E3D /* NSDictionary+MFConvenience.m in Sources */, AFBB968C1FBA3A9A0008D868 /* MVMCoreDismissViewControllerOperation.m in Sources */, AFBB96BA1FBA3CEC0008D868 /* MVMCoreActionHandler.m in Sources */, @@ -845,7 +871,7 @@ AFBB965F1FBA3A570008D868 /* MFFreebeeOperation.m in Sources */, AFBB96901FBA3A9A0008D868 /* MVMCoreNavigationObject.m in Sources */, 946EE1AB237B5C940036751F /* Decoder.swift in Sources */, - 946EE1BC237B691A0036751F /* ActionModel.swift in Sources */, + 946EE1BC237B691A0036751F /* ActionOpenPage.swift in Sources */, AFBB96A61FBA3A9A0008D868 /* MVMCoreTopAlertOperation.m in Sources */, 881D26931FCC9D180079C521 /* MVMCoreErrorObject.m in Sources */, 946EE1B0237B5EF70036751F /* JSONHelper.swift in Sources */, @@ -854,11 +880,13 @@ 946EE1B2237B5F260036751F /* JSONValue.swift in Sources */, AFBB96971FBA3A9A0008D868 /* MVMCorePresentViewControllerOperation.m in Sources */, AFBB96581FBA3A570008D868 /* FreeBeeAuthObject.m in Sources */, + 01F2A04E23A82CF500D954D8 /* ActionPopup.swift in Sources */, AF43A5781FBA5B7C008E9347 /* MVMCoreJSONConstants.m in Sources */, AFBB96691FBA3A570008D868 /* MVMCoreRequestParameters.m in Sources */, AFED77A31FCCA29400BAE689 /* MVMCoreViewControllerNibMappingObject.m in Sources */, 8876D5EB1FB50AB000EB2E3D /* NSDecimalNumber+MFConvenience.m in Sources */, AFBB96A41FBA3A9A0008D868 /* MVMCoreTopAlertObject.m in Sources */, + 01F2A03923A812DD00D954D8 /* ActionOpenUrl.swift in Sources */, AFBB96351FBA34310008D868 /* MVMCoreErrorConstants.m in Sources */, AFBB969C1FBA3A9A0008D868 /* MVMCoreAlertHandler.m in Sources */, AF43A5881FBB67D6008E9347 /* MVMCoreActionUtility.m in Sources */, @@ -866,17 +894,21 @@ AF43A57C1FBA5E6A008E9347 /* MVMCoreHardcodedStringsConstants.m in Sources */, AFBB965D1FBA3A570008D868 /* MFFreebeeHandler.m in Sources */, AFEEE81F1FCDF3CA00B5EDD0 /* MVMCoreLoggingHandler.m in Sources */, + 01F2A05223A8325100D954D8 /* ModelMapping.swift in Sources */, AFBB969E1FBA3A9A0008D868 /* MVMCoreAlertObject.m in Sources */, 8876D5F51FB50AB000EB2E3D /* UILabel+MFCustom.m in Sources */, + 01F2A05423A83E9200D954D8 /* KeyedDecodingContainer+CodingKey.swift in Sources */, AFBB96B31FBA3B590008D868 /* MVMCoreGetterUtility.m in Sources */, AF43A7071FC4D7A2008E9347 /* MVMCoreObject.m in Sources */, 01DF561421F90ADC00CC099B /* Dictionary+MFConvenience.swift in Sources */, AFBB96B11FBA3B590008D868 /* MVMCoreDispatchUtility.m in Sources */, 946EE1A3237B59C30036751F /* Model.swift in Sources */, + 01F2A05023A82D0800D954D8 /* ActionTopAlert.swift in Sources */, AFBB965B1FBA3A570008D868 /* FreeBeeUrlObject.m in Sources */, AFEA17A9209B6A1C00BC6740 /* MVMCoreBlockOperation.m in Sources */, AF43A70A1FC4F415008E9347 /* MVMCoreCache.m in Sources */, AF43A6FF1FBE3252008E9347 /* Reachability.m in Sources */, + 01F2A03B23A8159900D954D8 /* ActionOpenApp.swift in Sources */, AFBB96921FBA3A9A0008D868 /* MVMCoreNavigationOperation.m in Sources */, AFBB96611FBA3A570008D868 /* MVMCoreLoadObject.m in Sources */, 946EE1B4237B619D0036751F /* Encoder.swift in Sources */, diff --git a/MVMCore/MVMCore/Models/ActionType/ActionCall.swift b/MVMCore/MVMCore/Models/ActionType/ActionCall.swift new file mode 100644 index 0000000..d971cf5 --- /dev/null +++ b/MVMCore/MVMCore/Models/ActionType/ActionCall.swift @@ -0,0 +1,17 @@ +// +// ActionCall.swift +// MVMCore +// +// Created by Suresh, Kamlesh on 12/16/19. +// Copyright © 2019 myverizon. All rights reserved. +// + +import Foundation + +@objcMembers public class ActionCall: ActionProtocol { + public static var identifier: String = "call" + public var callNumber: String + public init(callNumber: String) { + self.callNumber = callNumber + } +} diff --git a/MVMCore/MVMCore/Models/ActionType/ActionModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionModel.swift deleted file mode 100644 index 8b1158c..0000000 --- a/MVMCore/MVMCore/Models/ActionType/ActionModel.swift +++ /dev/null @@ -1,17 +0,0 @@ -// -// ActionModel.swift -// MVMCore -// -// Created by Suresh, Kamlesh on 10/3/19. -// Copyright © 2019 Suresh, Kamlesh. All rights reserved. -// - -import Foundation - -@objcMembers public class ActionModel: Codable { - public var actionType: String? - - public init(actionType: String?) { - self.actionType = actionType - } -} diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenApp.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenApp.swift new file mode 100644 index 0000000..34b7581 --- /dev/null +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenApp.swift @@ -0,0 +1,17 @@ +// +// ActionOpenApp.swift +// MVMCore +// +// Created by Suresh, Kamlesh on 12/16/19. +// Copyright © 2019 myverizon. All rights reserved. +// + +import Foundation + +@objcMembers public class ActionOpenApp: ActionProtocol { + public static var identifier: String = "openApp" + public var appUrl: String + public init(appUrl: String) { + self.appUrl = appUrl + } +} diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenPage.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenPage.swift new file mode 100644 index 0000000..c51e2a8 --- /dev/null +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenPage.swift @@ -0,0 +1,17 @@ +// +// ActionModel.swift +// MVMCore +// +// Created by Suresh, Kamlesh on 10/3/19. +// Copyright © 2019 Suresh, Kamlesh. All rights reserved. +// + +import Foundation + +@objcMembers public class ActionOpenPage: ActionProtocol { + public static var identifier: String = "openPage" + public var pageType: String + public init(pageType: String) { + self.pageType = pageType + } +} diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift new file mode 100644 index 0000000..6f0c3f7 --- /dev/null +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift @@ -0,0 +1,17 @@ +// +// ActionOpenUrl.swift +// MVMCore +// +// Created by Suresh, Kamlesh on 12/16/19. +// Copyright © 2019 myverizon. All rights reserved. +// + +import Foundation + +@objcMembers public class ActionOpenUrl: ActionProtocol { + public static var identifier: String = "openUrl" + public var browserUrl: String + public init(browserUrl: String) { + self.browserUrl = browserUrl + } +} diff --git a/MVMCore/MVMCore/Models/ActionType/ActionPopup.swift b/MVMCore/MVMCore/Models/ActionType/ActionPopup.swift new file mode 100644 index 0000000..bde9339 --- /dev/null +++ b/MVMCore/MVMCore/Models/ActionType/ActionPopup.swift @@ -0,0 +1,17 @@ +// +// ActionPopup.swift +// MVMCore +// +// Created by Suresh, Kamlesh on 12/16/19. +// Copyright © 2019 myverizon. All rights reserved. +// + +import Foundation + +@objcMembers public class ActionPopup: ActionProtocol { + public static var identifier: String = "popup" + public var pageType: String + public init(pageType: String) { + self.pageType = pageType + } +} diff --git a/MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift b/MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift new file mode 100644 index 0000000..d4505cb --- /dev/null +++ b/MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift @@ -0,0 +1,23 @@ +// +// ActionProtocol.swift +// MVMCore +// +// Created by Suresh, Kamlesh on 12/16/19. +// Copyright © 2019 myverizon. All rights reserved. +// + +import Foundation + +public enum ActionCodingKey: String, CodingKey { + case type +} + +public protocol ActionProtocol: Model { + var type: String? { get } +} + +extension ActionProtocol { + public var type: String? { + get { return Self.identifier } + } +} diff --git a/MVMCore/MVMCore/Models/ActionType/ActionTopAlert.swift b/MVMCore/MVMCore/Models/ActionType/ActionTopAlert.swift new file mode 100644 index 0000000..64fd7e5 --- /dev/null +++ b/MVMCore/MVMCore/Models/ActionType/ActionTopAlert.swift @@ -0,0 +1,17 @@ +// +// ActionTopAlert.swift +// MVMCore +// +// Created by Suresh, Kamlesh on 12/16/19. +// Copyright © 2019 myverizon. All rights reserved. +// + +import Foundation + +@objcMembers public class ActionTopAlert: ActionProtocol { + public static var identifier: String = "topAlert" + public var pageType: String + public init(pageType: String) { + self.pageType = pageType + } +} diff --git a/MVMCore/MVMCore/Models/Extensions/KeyedDecodingContainer+CodingKey.swift b/MVMCore/MVMCore/Models/Extensions/KeyedDecodingContainer+CodingKey.swift new file mode 100644 index 0000000..e54ade6 --- /dev/null +++ b/MVMCore/MVMCore/Models/Extensions/KeyedDecodingContainer+CodingKey.swift @@ -0,0 +1,34 @@ +// +// KeyedDecodingContainer+Action.swift +// MVMCore +// +// Created by Suresh, Kamlesh on 12/16/19. +// Copyright © 2019 myverizon. All rights reserved. +// + +import Foundation + +extension KeyedDecodingContainer where Key : CodingKey { +// private enum TypeCodingKey: String, CodingKey { +// case type +// } + +// public func decode(codingKey: KeyedDecodingContainer.Key) throws -> ActionProtocol { +// return try decode(codingKey: codingKey, typeCodingKey: TypeCodingKey.type) +// } +// +// public func decodeActionIfPresent(codingKey: KeyedDecodingContainer.Key) throws -> ActionProtocol? { +// return try decodeIfPresent(codingKey: codingKey, typeCodingKey: TypeCodingKey.type) +// } +// +// public func decodeActionArray(codingKey: KeyedDecodingContainer.Key) throws -> [ActionProtocol] { +// guard let models = try decodeArray(codingKey: codingKey, typeCodingKey: TypeCodingKey.type) as? [ActionProtocol] else { +// throw ModelRegistry.Error.decoderError +// } +// return models +// } +// +// public func decodeActionArrayIfPresent(codingKey: KeyedDecodingContainer.Key) throws -> [ActionProtocol]? { +// return try decodeArrayIfPresent(codingKey: codingKey, typeCodingKey: TypeCodingKey.type) as? [ActionProtocol] +// } +} diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index 3e3fc3d..cb327dc 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -45,27 +45,29 @@ extension KeyedDecodingContainer where Key: CodingKey { //MARK: - DecodeIfPresent public func decodeIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> T? { + do { + let meta = try self.nestedContainer(keyedBy: C.self, forKey: codingKey) + guard let type = try meta.decodeIfPresent(String.self, forKey: typeCodingKey) else { + return nil + } - //get the type string - let meta = try self.nestedContainer(keyedBy: C.self, forKey: codingKey) - guard let type = try meta.decodeIfPresent(String.self, forKey: typeCodingKey) else { + //get the type + guard let found = ModelRegistry.types[type] else { + MVMCoreLoggingHandler.logDebugMessage(withDelegate: "Model not mapped: \(type)") + throw ModelRegistry.Error.decoderErrorModelNotMapped + } + + //decode the type using the decoder + let model = try found.mvmdecode(keyedContainer: self, codingKey: codingKey) + + guard let m = model as? T else { + throw ModelRegistry.Error.decoderError + } + + return m + } catch { return nil } - - //get the type - guard let found = ModelRegistry.types[type] else { - MVMCoreLoggingHandler.logDebugMessage(withDelegate: "Model not mapped: \(type)") - throw ModelRegistry.Error.decoderErrorModelNotMapped - } - - //decode the type using the decoder - let model = try found.mvmdecode(keyedContainer: self, codingKey: codingKey) - - guard let m = model as? T else { - throw ModelRegistry.Error.decoderError - } - - return m } diff --git a/MVMCore/MVMCore/Models/ModelMapping.swift b/MVMCore/MVMCore/Models/ModelMapping.swift new file mode 100644 index 0000000..0e3ea86 --- /dev/null +++ b/MVMCore/MVMCore/Models/ModelMapping.swift @@ -0,0 +1,20 @@ +// +// ModelMapping.swift +// MVMCore +// +// Created by Suresh, Kamlesh on 12/16/19. +// Copyright © 2019 myverizon. All rights reserved. +// + +import Foundation + +@objcMembers public class ModelMapping: NSObject { + public static func registerObjects() { + ModelRegistry.register(ActionOpenPage.self) + ModelRegistry.register(ActionOpenUrl.self) + ModelRegistry.register(ActionOpenApp.self) + ModelRegistry.register(ActionCall.self) + ModelRegistry.register(ActionPopup.self) + ModelRegistry.register(ActionTopAlert.self) + } +} diff --git a/MVMCore/MVMCore/Session/MVMCoreSessionObject.m b/MVMCore/MVMCore/Session/MVMCoreSessionObject.m index d094b0b..92803f7 100644 --- a/MVMCore/MVMCore/Session/MVMCoreSessionObject.m +++ b/MVMCore/MVMCore/Session/MVMCoreSessionObject.m @@ -9,6 +9,7 @@ #import "MVMCoreSessionObject.h" #import "MVMCoreObject.h" #import "MVMCoreActionUtility.h" +#import @implementation MVMCoreSessionObject @@ -20,6 +21,7 @@ } + (nullable instancetype)sharedGlobal { + [ModelMapping registerObjects]; return [MVMCoreActionUtility initializerClassCheck:[MVMCoreObject sharedInstance].session classToVerify:self]; } From e1ecb35531b2fe0a488ef8e7a5aeaf28c26d6709 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 18 Dec 2019 13:14:56 -0500 Subject: [PATCH 24/50] remove unused code --- .../MVMCore/Models/Model/ModelRegistry.swift | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index b811646..ee741bf 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -80,27 +80,20 @@ extension KeyedDecodingContainer where Key: CodingKey { var models = [Model]() var container = try nestedUnkeyedContainer(forKey: codingKey) var containerCopy = container - - var i = 0 - let count = container.count ?? 0 - while !container.isAtEnd { - if i < count { - let nestedContainer = try container.nestedContainer(keyedBy: C.self) - if let identifier = try nestedContainer.decodeIfPresent(String.self, forKey: typeCodingKey) { - //get the type - guard let type = ModelRegistry.types[identifier] else { - throw ModelRegistry.Error.decoderErrorModelNotMapped - } - //now get the decoder to use for the type - let decoder = try containerCopy.superDecoder() - let model = try type.init(from: decoder) - models.append(model) + let nestedContainer = try container.nestedContainer(keyedBy: C.self) + if let identifier = try nestedContainer.decodeIfPresent(String.self, forKey: typeCodingKey) { + //get the type + guard let type = ModelRegistry.types[identifier] else { + throw ModelRegistry.Error.decoderErrorModelNotMapped } - i+=1 + //now get the decoder to use for the type + let decoder = try containerCopy.superDecoder() + let model = try type.init(from: decoder) + models.append(model) } } - return models.count > 0 ? models : nil + return models } /// Decodes an array of registered model based on the identifiers. From 326f761f4fe65849d5ea2be962d7c8c4b4d55d90 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 18 Dec 2019 13:24:11 -0500 Subject: [PATCH 25/50] Condensing catch --- MVMCore/MVMCore/Models/Model/ModelRegistry.swift | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index ee741bf..e73437c 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -49,13 +49,7 @@ extension KeyedDecodingContainer where Key: CodingKey { /// Decodes to a registered model based on the identifier, optional. public func decodeModelIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> T? { //get the identifier string - var container: KeyedDecodingContainer? - do { - container = try nestedContainer(keyedBy: C.self, forKey: codingKey) - } catch { - return nil - } - guard let identifier = try container?.decodeIfPresent(String.self, forKey: typeCodingKey) else { + guard let container = try? nestedContainer(keyedBy: C.self, forKey: codingKey), let identifier = try? container.decodeIfPresent(String.self, forKey: typeCodingKey) else { return nil } @@ -77,8 +71,10 @@ extension KeyedDecodingContainer where Key: CodingKey { /// Decodes an array of registered model based on the identifiers, optional. public func decodeModelsIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> [Model]? { + guard var container = try? nestedUnkeyedContainer(forKey: codingKey) else { + return nil + } var models = [Model]() - var container = try nestedUnkeyedContainer(forKey: codingKey) var containerCopy = container while !container.isAtEnd { let nestedContainer = try container.nestedContainer(keyedBy: C.self) From 2b0b4cf91a5b1372b70531558ca031c7481a3d8b Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 18 Dec 2019 13:26:15 -0500 Subject: [PATCH 26/50] use helper function for getting type --- MVMCore/MVMCore/Models/Model/ModelRegistry.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index e73437c..f1391c1 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -54,7 +54,7 @@ extension KeyedDecodingContainer where Key: CodingKey { } //get the type - guard let type = ModelRegistry.types[identifier] else { + guard let type = ModelRegistry.getType(for: identifier) else { MVMCoreLoggingHandler.logDebugMessage(withDelegate: "Model not mapped: \(identifier)") throw ModelRegistry.Error.decoderErrorModelNotMapped } @@ -80,7 +80,7 @@ extension KeyedDecodingContainer where Key: CodingKey { let nestedContainer = try container.nestedContainer(keyedBy: C.self) if let identifier = try nestedContainer.decodeIfPresent(String.self, forKey: typeCodingKey) { //get the type - guard let type = ModelRegistry.types[identifier] else { + guard let type = ModelRegistry.getType(for: identifier) else { throw ModelRegistry.Error.decoderErrorModelNotMapped } //now get the decoder to use for the type From 6f6575c43ed5d2add215c5283b107d440752ae7b Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 18 Dec 2019 16:07:01 -0500 Subject: [PATCH 27/50] Further name changes --- MVMCore/MVMCore/Models/Model/Model.swift | 16 +++++------ .../MVMCore/Models/Model/ModelRegistry.swift | 28 +++++++++---------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/MVMCore/MVMCore/Models/Model/Model.swift b/MVMCore/MVMCore/Models/Model/Model.swift index 544cb3a..936c548 100644 --- a/MVMCore/MVMCore/Models/Model/Model.swift +++ b/MVMCore/MVMCore/Models/Model/Model.swift @@ -13,31 +13,29 @@ public protocol Model: Codable { static var identifier: String { get } /// Convenience function to decode to model using a keyed container. - static func decode(keyedContainer: KeyedDecodingContainer, codingKey: K) throws -> Self? + static func decode(keyedContainer: KeyedDecodingContainer, codingKey: K) throws -> Self? /// Convenience function to decode to model using an unkeyed container. static func decode(unkeyedContainer: inout UnkeyedDecodingContainer) throws -> Self? /// Convenience function to encode model using a keyed container. - func encode(keyedContainer: inout KeyedEncodingContainer, codingKey: K) throws + func encode(keyedContainer: inout KeyedEncodingContainer, codingKey: K) throws /// Convenience function to encode model using an unkeyed container. func encode(unkeyedContainer: inout UnkeyedEncodingContainer) throws } extension Model { - static public func decode(keyedContainer: KeyedDecodingContainer, codingKey: K) throws -> Self? { - let m = try keyedContainer.decodeIfPresent(self, forKey: codingKey) - return m + static public func decode(keyedContainer: KeyedDecodingContainer, codingKey: K) throws -> Self? { + return try keyedContainer.decodeIfPresent(self, forKey: codingKey) } static public func decode(unkeyedContainer: inout UnkeyedDecodingContainer) throws -> Self? { - let m = try unkeyedContainer.decodeIfPresent(self) - return m + return try unkeyedContainer.decodeIfPresent(self) } - public func encode(keyedContainer: inout KeyedEncodingContainer, codingKey: K) throws { + public func encode(keyedContainer: inout KeyedEncodingContainer, codingKey: K) throws { try keyedContainer.encode(self, forKey: codingKey) } - public func encode(unkeyedContainer: inout UnkeyedEncodingContainer) throws{ + public func encode(unkeyedContainer: inout UnkeyedEncodingContainer) throws { try unkeyedContainer.encode(self) } } diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index f1391c1..b4043c4 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -33,23 +33,23 @@ extension KeyedDecodingContainer where Key: CodingKey { //MARK: - Decode /// Decodes to a registered model based on the identifier - public func decodeModel(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> T { + public func decodeModel(codingKey: KeyedDecodingContainer.Key, typeCodingKey: TypeKey) throws -> M { guard let model: Model = try decodeModelIfPresent(codingKey: codingKey, typeCodingKey: typeCodingKey) else { throw ModelRegistry.Error.decoderErrorObjectNotPresent } - guard let m = model as? T else { + if let model = model as? M { + return model + } else { throw ModelRegistry.Error.decoderError } - - return m } //MARK: - DecodeIfPresent /// Decodes to a registered model based on the identifier, optional. - public func decodeModelIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> T? { + public func decodeModelIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: TypeKey) throws -> M? { //get the identifier string - guard let container = try? nestedContainer(keyedBy: C.self, forKey: codingKey), let identifier = try? container.decodeIfPresent(String.self, forKey: typeCodingKey) else { + guard let container = try? nestedContainer(keyedBy: TypeKey.self, forKey: codingKey), let identifier = try? container.decodeIfPresent(String.self, forKey: typeCodingKey) else { return nil } @@ -62,22 +62,22 @@ extension KeyedDecodingContainer where Key: CodingKey { //decode the type using the decoder let model = try type.decode(keyedContainer: self, codingKey: codingKey) - guard let m = model as? T else { + if let model = model as? M { + return model + } else { throw ModelRegistry.Error.decoderError } - - return m } /// Decodes an array of registered model based on the identifiers, optional. - public func decodeModelsIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> [Model]? { + public func decodeModelsIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: TypeKey) throws -> [Model]? { guard var container = try? nestedUnkeyedContainer(forKey: codingKey) else { return nil } var models = [Model]() var containerCopy = container while !container.isAtEnd { - let nestedContainer = try container.nestedContainer(keyedBy: C.self) + let nestedContainer = try container.nestedContainer(keyedBy: TypeKey.self) if let identifier = try nestedContainer.decodeIfPresent(String.self, forKey: typeCodingKey) { //get the type guard let type = ModelRegistry.getType(for: identifier) else { @@ -93,7 +93,7 @@ extension KeyedDecodingContainer where Key: CodingKey { } /// Decodes an array of registered model based on the identifiers. - public func decodeModels(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> [Model] { + public func decodeModels(codingKey: KeyedDecodingContainer.Key, typeCodingKey: TypeKey) throws -> [Model] { guard let models: [Model] = try decodeModelsIfPresent(codingKey: codingKey, typeCodingKey: typeCodingKey) else { throw ModelRegistry.Error.decoderErrorObjectNotPresent } @@ -105,9 +105,9 @@ extension KeyedEncodingContainer where Key: CodingKey { /// Encodes a model, optional. public mutating func encodeModelIfPresent(_ value: Model?, forKey key: KeyedEncodingContainer.Key) throws { - if let v = value { + if let value = value { let encoder = self.superEncoder(forKey: key) - try v.encode(to: encoder) + try value.encode(to: encoder) } } From 7c1bef990bbacc754c5bff2f2c98cbfd551555af Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 8 Jan 2020 13:11:11 -0500 Subject: [PATCH 28/50] property wrappers --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 16 ++++++++++++ .../Utility/PropertyWrappers/Clamping.swift | 26 +++++++++++++++++++ .../PropertyWrappers/UnitInterval.swift | 20 ++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 MVMCore/MVMCore/Utility/PropertyWrappers/Clamping.swift create mode 100644 MVMCore/MVMCore/Utility/PropertyWrappers/UnitInterval.swift diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index 0e4cad7..26f0ec2 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -149,6 +149,8 @@ AFFCFA681FCCC0D700FD0730 /* MVMCoreLoadingViewControllerProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = AFFCFA641FCCC0D600FD0730 /* MVMCoreLoadingViewControllerProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; D282AAB62240085300C46919 /* MVMCoreGetterUtility+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D282AAB52240085300C46919 /* MVMCoreGetterUtility+Extension.swift */; }; D282AAB82240342D00C46919 /* NSNumber+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D282AAB72240342D00C46919 /* NSNumber+Extension.swift */; }; + D2DEDCB723C63F3B00C44CC4 /* Clamping.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2DEDCB623C63F3B00C44CC4 /* Clamping.swift */; }; + D2DEDCB923C6400600C44CC4 /* UnitInterval.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2DEDCB823C6400600C44CC4 /* UnitInterval.swift */; }; D2E1FAD92260C3E400AEFD8C /* DelegateObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E1FAD82260C3E400AEFD8C /* DelegateObject.swift */; }; /* End PBXBuildFile section */ @@ -289,6 +291,8 @@ AFFCFA641FCCC0D600FD0730 /* MVMCoreLoadingViewControllerProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreLoadingViewControllerProtocol.h; sourceTree = ""; }; D282AAB52240085300C46919 /* MVMCoreGetterUtility+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MVMCoreGetterUtility+Extension.swift"; sourceTree = ""; }; D282AAB72240342D00C46919 /* NSNumber+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSNumber+Extension.swift"; sourceTree = ""; }; + D2DEDCB623C63F3B00C44CC4 /* Clamping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Clamping.swift; sourceTree = ""; }; + D2DEDCB823C6400600C44CC4 /* UnitInterval.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnitInterval.swift; sourceTree = ""; }; D2E1FAD82260C3E400AEFD8C /* DelegateObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DelegateObject.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -353,6 +357,7 @@ 881D26901FCC9D180079C521 /* MVMCoreOperation.m */, AFEA17A6209B6A1C00BC6740 /* MVMCoreBlockOperation.h */, AFEA17A7209B6A1C00BC6740 /* MVMCoreBlockOperation.m */, + D2DEDCB523C63F1800C44CC4 /* PropertyWrappers */, AFBB96E71FBA4A260008D868 /* HardCodedServerResponse */, AFBB96AB1FBA3B590008D868 /* Helpers */, ); @@ -654,6 +659,15 @@ path = LoadingOverlay; sourceTree = ""; }; + D2DEDCB523C63F1800C44CC4 /* PropertyWrappers */ = { + isa = PBXGroup; + children = ( + D2DEDCB623C63F3B00C44CC4 /* Clamping.swift */, + D2DEDCB823C6400600C44CC4 /* UnitInterval.swift */, + ); + path = PropertyWrappers; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -850,6 +864,7 @@ 881D26931FCC9D180079C521 /* MVMCoreErrorObject.m in Sources */, 946EE1B0237B5EF70036751F /* JSONHelper.swift in Sources */, 30349BF21FCCA78A00546A1E /* MVMCoreSessionTimeHandler.m in Sources */, + D2DEDCB923C6400600C44CC4 /* UnitInterval.swift in Sources */, 8876D5E91FB50AB000EB2E3D /* NSArray+MFConvenience.m in Sources */, 946EE1B2237B5F260036751F /* JSONValue.swift in Sources */, AFBB96971FBA3A9A0008D868 /* MVMCorePresentViewControllerOperation.m in Sources */, @@ -870,6 +885,7 @@ 8876D5F51FB50AB000EB2E3D /* UILabel+MFCustom.m in Sources */, AFBB96B31FBA3B590008D868 /* MVMCoreGetterUtility.m in Sources */, AF43A7071FC4D7A2008E9347 /* MVMCoreObject.m in Sources */, + D2DEDCB723C63F3B00C44CC4 /* Clamping.swift in Sources */, 01DF561421F90ADC00CC099B /* Dictionary+MFConvenience.swift in Sources */, AFBB96B11FBA3B590008D868 /* MVMCoreDispatchUtility.m in Sources */, 946EE1A3237B59C30036751F /* Model.swift in Sources */, diff --git a/MVMCore/MVMCore/Utility/PropertyWrappers/Clamping.swift b/MVMCore/MVMCore/Utility/PropertyWrappers/Clamping.swift new file mode 100644 index 0000000..06008f9 --- /dev/null +++ b/MVMCore/MVMCore/Utility/PropertyWrappers/Clamping.swift @@ -0,0 +1,26 @@ +// +// Clamping.swift +// MVMCore +// +// Created by Scott Pfeil on 1/8/20. +// Copyright © 2020 myverizon. All rights reserved. +// +// Clamps the value between a given range. + +import Foundation + +@propertyWrapper +public struct Clamping { + private var value: Value + private let range: ClosedRange + + init(range: ClosedRange) { + self.value = range.lowerBound + self.range = range + } + + public var wrappedValue: Value { + get { value } + set { value = min(max(range.lowerBound, newValue), range.upperBound) } + } +} diff --git a/MVMCore/MVMCore/Utility/PropertyWrappers/UnitInterval.swift b/MVMCore/MVMCore/Utility/PropertyWrappers/UnitInterval.swift new file mode 100644 index 0000000..cf25308 --- /dev/null +++ b/MVMCore/MVMCore/Utility/PropertyWrappers/UnitInterval.swift @@ -0,0 +1,20 @@ +// +// UnitInterval.swift +// MVMCore +// +// Created by Scott Pfeil on 1/8/20. +// Copyright © 2020 myverizon. All rights reserved. +// +// Clamps the value between 0 and 1 + +import Foundation + +@propertyWrapper +public struct UnitInterval { + @Clamping(range: 0...1) + public var wrappedValue: Value + + public init(wrappedValue value: Value) { + self.wrappedValue = value + } +} From 74f7826e4be4d466bff0515aa6c36876468b7d1f Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 8 Jan 2020 13:22:47 -0500 Subject: [PATCH 29/50] Colors --- MVMCore/MVMCore/Utility/PropertyWrappers/Clamping.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Utility/PropertyWrappers/Clamping.swift b/MVMCore/MVMCore/Utility/PropertyWrappers/Clamping.swift index 06008f9..b8bed45 100644 --- a/MVMCore/MVMCore/Utility/PropertyWrappers/Clamping.swift +++ b/MVMCore/MVMCore/Utility/PropertyWrappers/Clamping.swift @@ -14,7 +14,7 @@ public struct Clamping { private var value: Value private let range: ClosedRange - init(range: ClosedRange) { + public init(range: ClosedRange) { self.value = range.lowerBound self.range = range } From e2885b0f78c5906e1349389822e31e5c5c469899 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 8 Jan 2020 14:27:11 -0500 Subject: [PATCH 30/50] Percent --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 4 +++ .../Utility/PropertyWrappers/Percent.swift | 31 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 MVMCore/MVMCore/Utility/PropertyWrappers/Percent.swift diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index 68c281d..57a110b 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -159,6 +159,7 @@ D282AAB82240342D00C46919 /* NSNumber+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D282AAB72240342D00C46919 /* NSNumber+Extension.swift */; }; D2DEDCB723C63F3B00C44CC4 /* Clamping.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2DEDCB623C63F3B00C44CC4 /* Clamping.swift */; }; D2DEDCB923C6400600C44CC4 /* UnitInterval.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2DEDCB823C6400600C44CC4 /* UnitInterval.swift */; }; + D2DEDCBB23C65BC300C44CC4 /* Percent.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2DEDCBA23C65BC300C44CC4 /* Percent.swift */; }; D2E1FAD92260C3E400AEFD8C /* DelegateObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E1FAD82260C3E400AEFD8C /* DelegateObject.swift */; }; /* End PBXBuildFile section */ @@ -309,6 +310,7 @@ D282AAB72240342D00C46919 /* NSNumber+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSNumber+Extension.swift"; sourceTree = ""; }; D2DEDCB623C63F3B00C44CC4 /* Clamping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Clamping.swift; sourceTree = ""; }; D2DEDCB823C6400600C44CC4 /* UnitInterval.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnitInterval.swift; sourceTree = ""; }; + D2DEDCBA23C65BC300C44CC4 /* Percent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Percent.swift; sourceTree = ""; }; D2E1FAD82260C3E400AEFD8C /* DelegateObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DelegateObject.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -688,6 +690,7 @@ children = ( D2DEDCB623C63F3B00C44CC4 /* Clamping.swift */, D2DEDCB823C6400600C44CC4 /* UnitInterval.swift */, + D2DEDCBA23C65BC300C44CC4 /* Percent.swift */, ); path = PropertyWrappers; sourceTree = ""; @@ -930,6 +933,7 @@ 946EE1B4237B619D0036751F /* Encoder.swift in Sources */, AFBB96941FBA3A9A0008D868 /* MVMCorePresentAnimationOperation.m in Sources */, AF43A5841FBB66DE008E9347 /* MVMCoreConstants.m in Sources */, + D2DEDCBB23C65BC300C44CC4 /* Percent.swift in Sources */, AFBB966A1FBA3A570008D868 /* MVMCoreLoadRequestOperation.m in Sources */, 8876D5F31FB50AB000EB2E3D /* UIFont+MFSpacing.m in Sources */, D282AAB82240342D00C46919 /* NSNumber+Extension.swift in Sources */, diff --git a/MVMCore/MVMCore/Utility/PropertyWrappers/Percent.swift b/MVMCore/MVMCore/Utility/PropertyWrappers/Percent.swift new file mode 100644 index 0000000..2116306 --- /dev/null +++ b/MVMCore/MVMCore/Utility/PropertyWrappers/Percent.swift @@ -0,0 +1,31 @@ +// +// Progress.swift +// MVMCore +// +// Created by Scott Pfeil on 1/8/20. +// Copyright © 2020 myverizon. All rights reserved. +// + +import Foundation + +@propertyWrapper +public struct Percent { + @Clamping(range: 0...100) + public var wrappedValue: CGFloat + + public init(wrappedValue value: CGFloat) { + self.wrappedValue = value + } +} + +extension Percent: Codable { + public init(from decoder: Decoder) throws { + let typeContainer = try decoder.singleValueContainer() + self.wrappedValue = try typeContainer.decode(CGFloat.self) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(wrappedValue) + } +} From a9da777f560b4987a17d6c77677bc2131e23c899 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 13 Jan 2020 09:38:40 -0500 Subject: [PATCH 31/50] Line items update --- .../MVMCore/Models/Model/ModelRegistry.swift | 81 +++++++++++++++---- 1 file changed, 65 insertions(+), 16 deletions(-) diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index 4c8cc15..2aa0256 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -75,22 +75,7 @@ extension KeyedDecodingContainer where Key: CodingKey { guard var container = try? nestedUnkeyedContainer(forKey: codingKey) else { return nil } - var models = [Model]() - var containerCopy = container - while !container.isAtEnd { - let nestedContainer = try container.nestedContainer(keyedBy: TypeKey.self) - if let identifier = try nestedContainer.decodeIfPresent(String.self, forKey: typeCodingKey) { - //get the type - guard let type = ModelRegistry.getType(for: identifier) else { - throw ModelRegistry.Error.decoderErrorModelNotMapped - } - //now get the decoder to use for the type - let decoder = try containerCopy.superDecoder() - let model = try type.init(from: decoder) - models.append(model) - } - } - return models + return try container.decodeModelsIfPresent(typeCodingKey: typeCodingKey) } /// Decodes an array of registered model based on the identifiers. @@ -100,6 +85,22 @@ extension KeyedDecodingContainer where Key: CodingKey { } return models } + + /// Decodes an array with arrays of models based on the identifiers, optional. + public func decodeModels2DIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: TypeKey) throws -> [[Model]]? { + guard var container = try? nestedUnkeyedContainer(forKey: codingKey) else { + return nil + } + return try container.decodeModels2DIfPresent(typeCodingKey: typeCodingKey) + } + + /// Decodes an array with arrays of models based on the identifiers. + public func decodeModels2D(codingKey: KeyedDecodingContainer.Key, typeCodingKey: TypeKey) throws -> [[Model]] { + guard let models: [[Model]] = try decodeModels2DIfPresent(codingKey: codingKey, typeCodingKey: typeCodingKey) else { + throw ModelRegistry.Error.decoderErrorObjectNotPresent + } + return models + } } extension KeyedEncodingContainer where Key: CodingKey { @@ -131,4 +132,52 @@ extension KeyedEncodingContainer where Key: CodingKey { try model.encode(unkeyedContainer: &unkeyedContainer) } } + + /// Convenience function for encoding the container into a list of lists of Models. needs instance type as input paramaeter list + public mutating func encodeModels2D(_ list: [[Model]]?, forKey key:KeyedEncodingContainer.Key) throws { + guard let list = list else { return } + var unkeyedContainer = self.nestedUnkeyedContainer(forKey: key) + for models in list { + var arrayunkeyedContainer = unkeyedContainer.nestedUnkeyedContainer() + for model in models { + try model.encode(unkeyedContainer: &arrayunkeyedContainer) + } + } + } +} + +extension UnkeyedDecodingContainer { + /// Decodes the container into a list of Models. + public mutating func decodeModelsIfPresent(typeCodingKey: TypeKey) throws -> [Model]? { + var models = [Model]() + var containerCopy = self + while !containerCopy.isAtEnd { + let nestedContainer = try containerCopy.nestedContainer(keyedBy: TypeKey.self) + if let identifier = try nestedContainer.decodeIfPresent(String.self, forKey: typeCodingKey) { + //get the type + guard let type = ModelRegistry.getType(for: identifier) else { + throw ModelRegistry.Error.decoderErrorModelNotMapped + } + //now get the decoder to use for the type + let decoder = try self.superDecoder() + let model = try type.init(from: decoder) + models.append(model) + } + } + return models + } + + /// Convenience function for decoding the container into a list of lists of Models. + public mutating func decodeModels2DIfPresent(typeCodingKey: TypeKey) throws -> [[Model]]? { + var modelLists = [[Model]]() + var containerCopy = self + while !containerCopy.isAtEnd { + var arraycontainerCopy = try containerCopy.nestedUnkeyedContainer() + guard let models = try arraycontainerCopy.decodeModelsIfPresent(typeCodingKey: typeCodingKey) else { + throw ModelRegistry.Error.decoderErrorModelNotMapped + } + modelLists.append(models) + } + return modelLists + } } From 68695e983930240fcd1dcb532e9be4e65f2d0b32 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 13 Jan 2020 15:28:52 -0500 Subject: [PATCH 32/50] move register to init for now dash line update temporary for legacy --- MVMCore/MVMCore/Session/MVMCoreSessionObject.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Session/MVMCoreSessionObject.m b/MVMCore/MVMCore/Session/MVMCoreSessionObject.m index 92803f7..52a8355 100644 --- a/MVMCore/MVMCore/Session/MVMCoreSessionObject.m +++ b/MVMCore/MVMCore/Session/MVMCoreSessionObject.m @@ -16,12 +16,12 @@ - (instancetype)init { if (self = [super init]) { self.session = [self createNSURLSession]; + [ModelMapping registerObjects]; } return self; } + (nullable instancetype)sharedGlobal { - [ModelMapping registerObjects]; return [MVMCoreActionUtility initializerClassCheck:[MVMCoreObject sharedInstance].session classToVerify:self]; } From 148e556ddbef4c5252b1a434152b4c37c74ee5ef Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 14 Jan 2020 09:12:11 -0500 Subject: [PATCH 33/50] make the error throwable --- MVMCore/MVMCore/Utility/MVMCoreErrorObject.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Utility/MVMCoreErrorObject.m b/MVMCore/MVMCore/Utility/MVMCoreErrorObject.m index 9b28934..2f16308 100644 --- a/MVMCore/MVMCore/Utility/MVMCoreErrorObject.m +++ b/MVMCore/MVMCore/Utility/MVMCoreErrorObject.m @@ -104,7 +104,7 @@ + (nullable instancetype)createErrorObjectForNSError:(nonnull NSError *)error location:(nullable NSString *)location { - MVMCoreErrorObject *errorObject = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[error localizedDescription] code:[error code] domain:ErrorDomainSystem location:location]; + MVMCoreErrorObject *errorObject = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[error localizedDescription] messageToLog:[error description] code:[error code] domain:ErrorDomainSystem location:location]; if ([error.domain isEqualToString:NSURLErrorDomain]) { errorObject.systemDomain = error.domain; if ([[MVMCoreObject sharedInstance].globalLoadDelegate respondsToSelector:@selector(getNativeScreenForRequestError:requestObject:)]) { From 03f387487f09072f397b80a6104680bbe4c5878f Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 14 Jan 2020 10:13:21 -0500 Subject: [PATCH 34/50] actionType fix --- MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift | 6 +++--- MVMCore/MVMCore/Models/Model/ModelRegistry.swift | 10 +++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift b/MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift index d4505cb..81d77f2 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift @@ -9,15 +9,15 @@ import Foundation public enum ActionCodingKey: String, CodingKey { - case type + case actionType } public protocol ActionProtocol: Model { - var type: String? { get } + var actionType: String? { get } } extension ActionProtocol { - public var type: String? { + public var actionType: String? { get { return Self.identifier } } } diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index 2aa0256..04a8f78 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -50,7 +50,9 @@ extension KeyedDecodingContainer where Key: CodingKey { /// Decodes to a registered model based on the identifier, optional. public func decodeModelIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: TypeKey) throws -> M? { //get the identifier string - guard let container = try? nestedContainer(keyedBy: TypeKey.self, forKey: codingKey), let identifier = try? container.decodeIfPresent(String.self, forKey: typeCodingKey) else { + guard contains(codingKey), + let container = try? nestedContainer(keyedBy: TypeKey.self, forKey: codingKey), + let identifier = try? container.decodeIfPresent(String.self, forKey: typeCodingKey) else { return nil } @@ -72,7 +74,8 @@ extension KeyedDecodingContainer where Key: CodingKey { /// Decodes an array of registered model based on the identifiers, optional. public func decodeModelsIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: TypeKey) throws -> [Model]? { - guard var container = try? nestedUnkeyedContainer(forKey: codingKey) else { + guard contains(codingKey), + var container = try? nestedUnkeyedContainer(forKey: codingKey) else { return nil } return try container.decodeModelsIfPresent(typeCodingKey: typeCodingKey) @@ -88,7 +91,8 @@ extension KeyedDecodingContainer where Key: CodingKey { /// Decodes an array with arrays of models based on the identifiers, optional. public func decodeModels2DIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: TypeKey) throws -> [[Model]]? { - guard var container = try? nestedUnkeyedContainer(forKey: codingKey) else { + guard contains(codingKey), + var container = try? nestedUnkeyedContainer(forKey: codingKey) else { return nil } return try container.decodeModels2DIfPresent(typeCodingKey: typeCodingKey) From 731f3b811a8af7fd8114ae2dcb9e9be9c42c4800 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Tue, 14 Jan 2020 21:26:03 -0500 Subject: [PATCH 35/50] openURL --- MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift index 6f0c3f7..a22dfc2 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift @@ -9,7 +9,7 @@ import Foundation @objcMembers public class ActionOpenUrl: ActionProtocol { - public static var identifier: String = "openUrl" + public static var identifier: String = "openURL" public var browserUrl: String public init(browserUrl: String) { self.browserUrl = browserUrl From a23efe668a20be74133b2ffec4665292a81b3f9e Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 15 Jan 2020 13:33:46 -0500 Subject: [PATCH 36/50] extra params --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 4 +++ .../Models/ActionType/ActionCall.swift | 2 ++ .../Models/ActionType/ActionOpenApp.swift | 2 ++ .../Models/ActionType/ActionOpenPage.swift | 2 ++ .../Models/ActionType/ActionOpenUrl.swift | 2 ++ .../Models/ActionType/ActionPopup.swift | 2 ++ .../Models/ActionType/ActionProtocol.swift | 2 ++ .../Models/ActionType/ActionTopAlert.swift | 2 ++ MVMCore/MVMCore/Models/JSON/JSONMap.swift | 31 +++++++++++++++++++ .../MFHardCodedServerResponse.h | 2 +- 10 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 MVMCore/MVMCore/Models/JSON/JSONMap.swift diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index 57a110b..cb5326b 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -21,6 +21,7 @@ /* End PBXAggregateTarget section */ /* Begin PBXBuildFile section */ + 01C851CF23CF7B260021F976 /* JSONMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01C851CE23CF7B260021F976 /* JSONMap.swift */; }; 01DF561421F90ADC00CC099B /* Dictionary+MFConvenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF561321F90ADC00CC099B /* Dictionary+MFConvenience.swift */; }; 01F2A03623A80A7300D954D8 /* ActionProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A03523A80A7300D954D8 /* ActionProtocol.swift */; }; 01F2A03923A812DD00D954D8 /* ActionOpenUrl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A03823A812DD00D954D8 /* ActionOpenUrl.swift */; }; @@ -164,6 +165,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 01C851CE23CF7B260021F976 /* JSONMap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONMap.swift; sourceTree = ""; }; 01DF561321F90ADC00CC099B /* Dictionary+MFConvenience.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Dictionary+MFConvenience.swift"; sourceTree = ""; }; 01F2A03523A80A7300D954D8 /* ActionProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionProtocol.swift; sourceTree = ""; }; 01F2A03823A812DD00D954D8 /* ActionOpenUrl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionOpenUrl.swift; sourceTree = ""; }; @@ -437,6 +439,7 @@ children = ( 946EE1AF237B5EF70036751F /* JSONHelper.swift */, 946EE1B1237B5F260036751F /* JSONValue.swift */, + 01C851CE23CF7B260021F976 /* JSONMap.swift */, ); path = JSON; sourceTree = ""; @@ -878,6 +881,7 @@ AFBB96991FBA3A9A0008D868 /* MVMCoreAlertController.m in Sources */, 881D26941FCC9D180079C521 /* MVMCoreOperation.m in Sources */, AFED77A41FCCA29400BAE689 /* MVMCoreViewControllerMappingObject.m in Sources */, + 01C851CF23CF7B260021F976 /* JSONMap.swift in Sources */, 01F2A04C23A82B1B00D954D8 /* ActionCall.swift in Sources */, 8876D5ED1FB50AB000EB2E3D /* NSDictionary+MFConvenience.m in Sources */, AFBB968C1FBA3A9A0008D868 /* MVMCoreDismissViewControllerOperation.m in Sources */, diff --git a/MVMCore/MVMCore/Models/ActionType/ActionCall.swift b/MVMCore/MVMCore/Models/ActionType/ActionCall.swift index d971cf5..9cef755 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionCall.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionCall.swift @@ -11,6 +11,8 @@ import Foundation @objcMembers public class ActionCall: ActionProtocol { public static var identifier: String = "call" public var callNumber: String + public var extraParameter: JSONValueDictionary? + public var analyticsData: JSONValueDictionary? public init(callNumber: String) { self.callNumber = callNumber } diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenApp.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenApp.swift index 34b7581..4552f6a 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenApp.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenApp.swift @@ -11,6 +11,8 @@ import Foundation @objcMembers public class ActionOpenApp: ActionProtocol { public static var identifier: String = "openApp" public var appUrl: String + public var extraParameter: JSONValueDictionary? + public var analyticsData: JSONValueDictionary? public init(appUrl: String) { self.appUrl = appUrl } diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenPage.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenPage.swift index c51e2a8..4efc54a 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenPage.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenPage.swift @@ -11,6 +11,8 @@ import Foundation @objcMembers public class ActionOpenPage: ActionProtocol { public static var identifier: String = "openPage" public var pageType: String + public var extraParameter: JSONValueDictionary? + public var analyticsData: JSONValueDictionary? public init(pageType: String) { self.pageType = pageType } diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift index 6f0c3f7..dd61bb4 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift @@ -11,6 +11,8 @@ import Foundation @objcMembers public class ActionOpenUrl: ActionProtocol { public static var identifier: String = "openUrl" public var browserUrl: String + public var extraParameter: JSONValueDictionary? + public var analyticsData: JSONValueDictionary? public init(browserUrl: String) { self.browserUrl = browserUrl } diff --git a/MVMCore/MVMCore/Models/ActionType/ActionPopup.swift b/MVMCore/MVMCore/Models/ActionType/ActionPopup.swift index bde9339..10d3d8c 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionPopup.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionPopup.swift @@ -11,6 +11,8 @@ import Foundation @objcMembers public class ActionPopup: ActionProtocol { public static var identifier: String = "popup" public var pageType: String + public var extraParameter: JSONValueDictionary? + public var analyticsData: JSONValueDictionary? public init(pageType: String) { self.pageType = pageType } diff --git a/MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift b/MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift index 81d77f2..d0959c4 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift @@ -14,6 +14,8 @@ public enum ActionCodingKey: String, CodingKey { public protocol ActionProtocol: Model { var actionType: String? { get } + var extraParameter: JSONValueDictionary? { get set } + var analyticsData: JSONValueDictionary? { get set } } extension ActionProtocol { diff --git a/MVMCore/MVMCore/Models/ActionType/ActionTopAlert.swift b/MVMCore/MVMCore/Models/ActionType/ActionTopAlert.swift index 64fd7e5..fe9aea9 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionTopAlert.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionTopAlert.swift @@ -11,6 +11,8 @@ import Foundation @objcMembers public class ActionTopAlert: ActionProtocol { public static var identifier: String = "topAlert" public var pageType: String + public var extraParameter: JSONValueDictionary? + public var analyticsData: JSONValueDictionary? public init(pageType: String) { self.pageType = pageType } diff --git a/MVMCore/MVMCore/Models/JSON/JSONMap.swift b/MVMCore/MVMCore/Models/JSON/JSONMap.swift new file mode 100644 index 0000000..28a3ee8 --- /dev/null +++ b/MVMCore/MVMCore/Models/JSON/JSONMap.swift @@ -0,0 +1,31 @@ +// +// JSONMap.swift +// MVMCore +// +// Created by Suresh, Kamlesh on 1/15/20. +// Copyright © 2020 myverizon. All rights reserved. +// + +import Foundation + + +@propertyWrapper +public struct JSONMap { + public var wrappedValue: JSONValueDictionary + + public init(wrappedValue value: JSONValueDictionary) { + self.wrappedValue = value + } +} + +extension JSONMap: Codable { + public init(from decoder: Decoder) throws { + let typeContainer = try decoder.singleValueContainer() + self.wrappedValue = try typeContainer.decode(JSONValueDictionary.self) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(wrappedValue) + } +} diff --git a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h index eb9fba9..efa33b6 100644 --- a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h +++ b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h @@ -9,7 +9,7 @@ #import #import "MVMCoreRequestParameters.h" -#define ENABLE_HARD_CODED_RESPONSE 0 && DEBUG +#define ENABLE_HARD_CODED_RESPONSE 1 && DEBUG #if ENABLE_HARD_CODED_RESPONSE From 34ea20934ac4290d3990347921c4bce44f517f93 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 15 Jan 2020 13:36:31 -0500 Subject: [PATCH 37/50] 0 --- .../Utility/HardCodedServerResponse/MFHardCodedServerResponse.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h index efa33b6..eb9fba9 100644 --- a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h +++ b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h @@ -9,7 +9,7 @@ #import #import "MVMCoreRequestParameters.h" -#define ENABLE_HARD_CODED_RESPONSE 1 && DEBUG +#define ENABLE_HARD_CODED_RESPONSE 0 && DEBUG #if ENABLE_HARD_CODED_RESPONSE From ccaba9b0b4bfdca1a07dfb2da4b5ea6ca54617ec Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 15 Jan 2020 16:29:36 -0500 Subject: [PATCH 38/50] action type --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 4 ++++ .../MVMCore/Models/ActionType/ActionBack.swift | 16 ++++++++++++++++ .../MVMCore/Models/ActionType/ActionCall.swift | 1 + .../Models/ActionType/ActionOpenApp.swift | 7 ++++--- .../Models/ActionType/ActionOpenPage.swift | 1 + .../Models/ActionType/ActionOpenUrl.swift | 1 + .../MVMCore/Models/ActionType/ActionPopup.swift | 1 + .../Models/ActionType/ActionProtocol.swift | 8 +------- .../Models/ActionType/ActionTopAlert.swift | 1 + MVMCore/MVMCore/Models/ModelMapping.swift | 1 + 10 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 MVMCore/MVMCore/Models/ActionType/ActionBack.swift diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index cb5326b..9fb4ce4 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -22,6 +22,7 @@ /* Begin PBXBuildFile section */ 01C851CF23CF7B260021F976 /* JSONMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01C851CE23CF7B260021F976 /* JSONMap.swift */; }; + 01C851D123CF97FE0021F976 /* ActionBack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01C851D023CF97FE0021F976 /* ActionBack.swift */; }; 01DF561421F90ADC00CC099B /* Dictionary+MFConvenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF561321F90ADC00CC099B /* Dictionary+MFConvenience.swift */; }; 01F2A03623A80A7300D954D8 /* ActionProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A03523A80A7300D954D8 /* ActionProtocol.swift */; }; 01F2A03923A812DD00D954D8 /* ActionOpenUrl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A03823A812DD00D954D8 /* ActionOpenUrl.swift */; }; @@ -166,6 +167,7 @@ /* Begin PBXFileReference section */ 01C851CE23CF7B260021F976 /* JSONMap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONMap.swift; sourceTree = ""; }; + 01C851D023CF97FE0021F976 /* ActionBack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionBack.swift; sourceTree = ""; }; 01DF561321F90ADC00CC099B /* Dictionary+MFConvenience.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Dictionary+MFConvenience.swift"; sourceTree = ""; }; 01F2A03523A80A7300D954D8 /* ActionProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionProtocol.swift; sourceTree = ""; }; 01F2A03823A812DD00D954D8 /* ActionOpenUrl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionOpenUrl.swift; sourceTree = ""; }; @@ -454,6 +456,7 @@ 01F2A04B23A82B1B00D954D8 /* ActionCall.swift */, 01F2A04D23A82CF500D954D8 /* ActionPopup.swift */, 01F2A04F23A82D0800D954D8 /* ActionTopAlert.swift */, + 01C851D023CF97FE0021F976 /* ActionBack.swift */, ); path = ActionType; sourceTree = ""; @@ -931,6 +934,7 @@ AFEA17A9209B6A1C00BC6740 /* MVMCoreBlockOperation.m in Sources */, AF43A70A1FC4F415008E9347 /* MVMCoreCache.m in Sources */, AF43A6FF1FBE3252008E9347 /* Reachability.m in Sources */, + 01C851D123CF97FE0021F976 /* ActionBack.swift in Sources */, 01F2A03B23A8159900D954D8 /* ActionOpenApp.swift in Sources */, AFBB96921FBA3A9A0008D868 /* MVMCoreNavigationOperation.m in Sources */, AFBB96611FBA3A570008D868 /* MVMCoreLoadObject.m in Sources */, diff --git a/MVMCore/MVMCore/Models/ActionType/ActionBack.swift b/MVMCore/MVMCore/Models/ActionType/ActionBack.swift new file mode 100644 index 0000000..07b0faf --- /dev/null +++ b/MVMCore/MVMCore/Models/ActionType/ActionBack.swift @@ -0,0 +1,16 @@ +// +// File.swift +// MVMCore +// +// Created by Suresh, Kamlesh on 1/15/20. +// Copyright © 2020 myverizon. All rights reserved. +// + +import Foundation + +@objcMembers public class ActionBack: ActionProtocol { + public static var identifier: String = "back" + public var actionType: String? + public var extraParameter: JSONValueDictionary? + public var analyticsData: JSONValueDictionary? +} diff --git a/MVMCore/MVMCore/Models/ActionType/ActionCall.swift b/MVMCore/MVMCore/Models/ActionType/ActionCall.swift index 9cef755..bfbf3b1 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionCall.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionCall.swift @@ -10,6 +10,7 @@ import Foundation @objcMembers public class ActionCall: ActionProtocol { public static var identifier: String = "call" + public var actionType: String? public var callNumber: String public var extraParameter: JSONValueDictionary? public var analyticsData: JSONValueDictionary? diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenApp.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenApp.swift index 4552f6a..455e8d2 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenApp.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenApp.swift @@ -10,10 +10,11 @@ import Foundation @objcMembers public class ActionOpenApp: ActionProtocol { public static var identifier: String = "openApp" - public var appUrl: String + public var actionType: String? + public var appURL: String public var extraParameter: JSONValueDictionary? public var analyticsData: JSONValueDictionary? - public init(appUrl: String) { - self.appUrl = appUrl + public init(appURL: String) { + self.appURL = appURL } } diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenPage.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenPage.swift index 4efc54a..6dc7397 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenPage.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenPage.swift @@ -10,6 +10,7 @@ import Foundation @objcMembers public class ActionOpenPage: ActionProtocol { public static var identifier: String = "openPage" + public var actionType: String? public var pageType: String public var extraParameter: JSONValueDictionary? public var analyticsData: JSONValueDictionary? diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift index dd61bb4..eaa397b 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift @@ -10,6 +10,7 @@ import Foundation @objcMembers public class ActionOpenUrl: ActionProtocol { public static var identifier: String = "openUrl" + public var actionType: String? public var browserUrl: String public var extraParameter: JSONValueDictionary? public var analyticsData: JSONValueDictionary? diff --git a/MVMCore/MVMCore/Models/ActionType/ActionPopup.swift b/MVMCore/MVMCore/Models/ActionType/ActionPopup.swift index 10d3d8c..a8a9efc 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionPopup.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionPopup.swift @@ -10,6 +10,7 @@ import Foundation @objcMembers public class ActionPopup: ActionProtocol { public static var identifier: String = "popup" + public var actionType: String? public var pageType: String public var extraParameter: JSONValueDictionary? public var analyticsData: JSONValueDictionary? diff --git a/MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift b/MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift index d0959c4..dc0f88f 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift @@ -13,13 +13,7 @@ public enum ActionCodingKey: String, CodingKey { } public protocol ActionProtocol: Model { - var actionType: String? { get } + var actionType: String? { get set } var extraParameter: JSONValueDictionary? { get set } var analyticsData: JSONValueDictionary? { get set } } - -extension ActionProtocol { - public var actionType: String? { - get { return Self.identifier } - } -} diff --git a/MVMCore/MVMCore/Models/ActionType/ActionTopAlert.swift b/MVMCore/MVMCore/Models/ActionType/ActionTopAlert.swift index fe9aea9..bf9ee8e 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionTopAlert.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionTopAlert.swift @@ -10,6 +10,7 @@ import Foundation @objcMembers public class ActionTopAlert: ActionProtocol { public static var identifier: String = "topAlert" + public var actionType: String? public var pageType: String public var extraParameter: JSONValueDictionary? public var analyticsData: JSONValueDictionary? diff --git a/MVMCore/MVMCore/Models/ModelMapping.swift b/MVMCore/MVMCore/Models/ModelMapping.swift index 0e3ea86..26d5ddc 100644 --- a/MVMCore/MVMCore/Models/ModelMapping.swift +++ b/MVMCore/MVMCore/Models/ModelMapping.swift @@ -16,5 +16,6 @@ import Foundation ModelRegistry.register(ActionCall.self) ModelRegistry.register(ActionPopup.self) ModelRegistry.register(ActionTopAlert.self) + ModelRegistry.register(ActionBack.self) } } From 2c78fa2e7ef00a74b6826760ba23b82867dbc1c3 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 15 Jan 2020 18:33:55 -0500 Subject: [PATCH 39/50] openURL --- MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift | 2 +- .../Utility/HardCodedServerResponse/MFHardCodedServerResponse.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift index eaa397b..d535db5 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift @@ -9,7 +9,7 @@ import Foundation @objcMembers public class ActionOpenUrl: ActionProtocol { - public static var identifier: String = "openUrl" + public static var identifier: String = "openURL" public var actionType: String? public var browserUrl: String public var extraParameter: JSONValueDictionary? diff --git a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h index eb9fba9..efa33b6 100644 --- a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h +++ b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h @@ -9,7 +9,7 @@ #import #import "MVMCoreRequestParameters.h" -#define ENABLE_HARD_CODED_RESPONSE 0 && DEBUG +#define ENABLE_HARD_CODED_RESPONSE 1 && DEBUG #if ENABLE_HARD_CODED_RESPONSE From 153dc072be306acf1ed8114c31443fbd7dd370c8 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 16 Jan 2020 14:14:51 -0500 Subject: [PATCH 40/50] 0 --- .../Utility/HardCodedServerResponse/MFHardCodedServerResponse.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h index efa33b6..eb9fba9 100644 --- a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h +++ b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h @@ -9,7 +9,7 @@ #import #import "MVMCoreRequestParameters.h" -#define ENABLE_HARD_CODED_RESPONSE 1 && DEBUG +#define ENABLE_HARD_CODED_RESPONSE 0 && DEBUG #if ENABLE_HARD_CODED_RESPONSE From 6e9a622ae58ddc90d62dce2dcaef0b34a0b2159d Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 16 Jan 2020 17:21:05 -0500 Subject: [PATCH 41/50] extrameters --- MVMCore/MVMCore/Models/ActionType/ActionBack.swift | 2 +- MVMCore/MVMCore/Models/ActionType/ActionCall.swift | 2 +- MVMCore/MVMCore/Models/ActionType/ActionOpenApp.swift | 2 +- MVMCore/MVMCore/Models/ActionType/ActionOpenPage.swift | 2 +- MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift | 2 +- MVMCore/MVMCore/Models/ActionType/ActionPopup.swift | 2 +- MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift | 2 +- MVMCore/MVMCore/Models/ActionType/ActionTopAlert.swift | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/MVMCore/MVMCore/Models/ActionType/ActionBack.swift b/MVMCore/MVMCore/Models/ActionType/ActionBack.swift index 07b0faf..4c93f94 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionBack.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionBack.swift @@ -11,6 +11,6 @@ import Foundation @objcMembers public class ActionBack: ActionProtocol { public static var identifier: String = "back" public var actionType: String? - public var extraParameter: JSONValueDictionary? + public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? } diff --git a/MVMCore/MVMCore/Models/ActionType/ActionCall.swift b/MVMCore/MVMCore/Models/ActionType/ActionCall.swift index bfbf3b1..198ab37 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionCall.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionCall.swift @@ -12,7 +12,7 @@ import Foundation public static var identifier: String = "call" public var actionType: String? public var callNumber: String - public var extraParameter: JSONValueDictionary? + public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? public init(callNumber: String) { self.callNumber = callNumber diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenApp.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenApp.swift index 455e8d2..0a2d838 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenApp.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenApp.swift @@ -12,7 +12,7 @@ import Foundation public static var identifier: String = "openApp" public var actionType: String? public var appURL: String - public var extraParameter: JSONValueDictionary? + public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? public init(appURL: String) { self.appURL = appURL diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenPage.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenPage.swift index 6dc7397..b78de5a 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenPage.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenPage.swift @@ -12,7 +12,7 @@ import Foundation public static var identifier: String = "openPage" public var actionType: String? public var pageType: String - public var extraParameter: JSONValueDictionary? + public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? public init(pageType: String) { self.pageType = pageType diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift index d535db5..af9871a 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift @@ -12,7 +12,7 @@ import Foundation public static var identifier: String = "openURL" public var actionType: String? public var browserUrl: String - public var extraParameter: JSONValueDictionary? + public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? public init(browserUrl: String) { self.browserUrl = browserUrl diff --git a/MVMCore/MVMCore/Models/ActionType/ActionPopup.swift b/MVMCore/MVMCore/Models/ActionType/ActionPopup.swift index a8a9efc..83bde62 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionPopup.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionPopup.swift @@ -12,7 +12,7 @@ import Foundation public static var identifier: String = "popup" public var actionType: String? public var pageType: String - public var extraParameter: JSONValueDictionary? + public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? public init(pageType: String) { self.pageType = pageType diff --git a/MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift b/MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift index dc0f88f..c6aeb72 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift @@ -14,6 +14,6 @@ public enum ActionCodingKey: String, CodingKey { public protocol ActionProtocol: Model { var actionType: String? { get set } - var extraParameter: JSONValueDictionary? { get set } + var extraParameters: JSONValueDictionary? { get set } var analyticsData: JSONValueDictionary? { get set } } diff --git a/MVMCore/MVMCore/Models/ActionType/ActionTopAlert.swift b/MVMCore/MVMCore/Models/ActionType/ActionTopAlert.swift index bf9ee8e..cbd2fbd 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionTopAlert.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionTopAlert.swift @@ -12,7 +12,7 @@ import Foundation public static var identifier: String = "topAlert" public var actionType: String? public var pageType: String - public var extraParameter: JSONValueDictionary? + public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? public init(pageType: String) { self.pageType = pageType From 694f465027ebbbd80ba5b11361301b0bde9e2411 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Fri, 17 Jan 2020 12:27:40 -0500 Subject: [PATCH 42/50] title --- MVMCore/MVMCore/Models/ActionType/ActionBack.swift | 2 ++ MVMCore/MVMCore/Models/ActionType/ActionCall.swift | 3 +++ MVMCore/MVMCore/Models/ActionType/ActionOpenApp.swift | 3 +++ MVMCore/MVMCore/Models/ActionType/ActionOpenPage.swift | 3 +++ MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift | 3 +++ MVMCore/MVMCore/Models/ActionType/ActionPopup.swift | 1 + MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift | 3 +++ MVMCore/MVMCore/Models/ActionType/ActionTopAlert.swift | 3 +++ .../HardCodedServerResponse/MFHardCodedServerResponse.h | 2 +- 9 files changed, 22 insertions(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Models/ActionType/ActionBack.swift b/MVMCore/MVMCore/Models/ActionType/ActionBack.swift index 4c93f94..2c074b1 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionBack.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionBack.swift @@ -13,4 +13,6 @@ import Foundation public var actionType: String? public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? + // Temporary fix till server changes + public var title: String? } diff --git a/MVMCore/MVMCore/Models/ActionType/ActionCall.swift b/MVMCore/MVMCore/Models/ActionType/ActionCall.swift index 198ab37..403cc89 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionCall.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionCall.swift @@ -14,6 +14,9 @@ import Foundation public var callNumber: String public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? + // Temporary fix till server changes + public var title: String? + public init(callNumber: String) { self.callNumber = callNumber } diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenApp.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenApp.swift index 0a2d838..d7fc8d5 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenApp.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenApp.swift @@ -14,6 +14,9 @@ import Foundation public var appURL: String public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? + // Temporary fix till server changes + public var title: String? + public init(appURL: String) { self.appURL = appURL } diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenPage.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenPage.swift index b78de5a..6e8935f 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenPage.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenPage.swift @@ -14,6 +14,9 @@ import Foundation public var pageType: String public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? + // Temporary fix till server changes + public var title: String? + public init(pageType: String) { self.pageType = pageType } diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift index af9871a..e827c69 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift @@ -14,6 +14,9 @@ import Foundation public var browserUrl: String public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? + // Temporary fix till server changes + public var title: String? + public init(browserUrl: String) { self.browserUrl = browserUrl } diff --git a/MVMCore/MVMCore/Models/ActionType/ActionPopup.swift b/MVMCore/MVMCore/Models/ActionType/ActionPopup.swift index 83bde62..bb75847 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionPopup.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionPopup.swift @@ -11,6 +11,7 @@ import Foundation @objcMembers public class ActionPopup: ActionProtocol { public static var identifier: String = "popup" public var actionType: String? + public var title: String? public var pageType: String public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? diff --git a/MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift b/MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift index c6aeb72..34f9b2c 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift @@ -16,4 +16,7 @@ public protocol ActionProtocol: Model { var actionType: String? { get set } var extraParameters: JSONValueDictionary? { get set } var analyticsData: JSONValueDictionary? { get set } + + // Temporary fix till server changes + var title: String? { get set } } diff --git a/MVMCore/MVMCore/Models/ActionType/ActionTopAlert.swift b/MVMCore/MVMCore/Models/ActionType/ActionTopAlert.swift index cbd2fbd..2173c76 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionTopAlert.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionTopAlert.swift @@ -14,6 +14,9 @@ import Foundation public var pageType: String public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? + // Temporary fix till server changes + public var title: String? + public init(pageType: String) { self.pageType = pageType } diff --git a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h index eb9fba9..efa33b6 100644 --- a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h +++ b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h @@ -9,7 +9,7 @@ #import #import "MVMCoreRequestParameters.h" -#define ENABLE_HARD_CODED_RESPONSE 0 && DEBUG +#define ENABLE_HARD_CODED_RESPONSE 1 && DEBUG #if ENABLE_HARD_CODED_RESPONSE From 2b27853d7722a5e43ed8eeba17e695a6bb0f62f4 Mon Sep 17 00:00:00 2001 From: "Xinlei(Ryan) Pan" Date: Tue, 21 Jan 2020 15:00:49 -0500 Subject: [PATCH 43/50] remove unneeded code --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 4 --- .../KeyedDecodingContainer+CodingKey.swift | 34 ------------------- .../MFHardCodedServerResponse.h | 2 +- 3 files changed, 1 insertion(+), 39 deletions(-) delete mode 100644 MVMCore/MVMCore/Models/Extensions/KeyedDecodingContainer+CodingKey.swift diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index 9fb4ce4..ae97d07 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -31,7 +31,6 @@ 01F2A04E23A82CF500D954D8 /* ActionPopup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A04D23A82CF500D954D8 /* ActionPopup.swift */; }; 01F2A05023A82D0800D954D8 /* ActionTopAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A04F23A82D0800D954D8 /* ActionTopAlert.swift */; }; 01F2A05223A8325100D954D8 /* ModelMapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A05123A8325100D954D8 /* ModelMapping.swift */; }; - 01F2A05423A83E9200D954D8 /* KeyedDecodingContainer+CodingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A05323A83E9200D954D8 /* KeyedDecodingContainer+CodingKey.swift */; }; 30349BF11FCCA78A00546A1E /* MVMCoreSessionTimeHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 30349BEF1FCCA78A00546A1E /* MVMCoreSessionTimeHandler.h */; settings = {ATTRIBUTES = (Public, ); }; }; 30349BF21FCCA78A00546A1E /* MVMCoreSessionTimeHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 30349BF01FCCA78A00546A1E /* MVMCoreSessionTimeHandler.m */; }; 881D26931FCC9D180079C521 /* MVMCoreErrorObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 881D268F1FCC9D180079C521 /* MVMCoreErrorObject.m */; }; @@ -176,7 +175,6 @@ 01F2A04D23A82CF500D954D8 /* ActionPopup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionPopup.swift; sourceTree = ""; }; 01F2A04F23A82D0800D954D8 /* ActionTopAlert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionTopAlert.swift; sourceTree = ""; }; 01F2A05123A8325100D954D8 /* ModelMapping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelMapping.swift; sourceTree = ""; }; - 01F2A05323A83E9200D954D8 /* KeyedDecodingContainer+CodingKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "KeyedDecodingContainer+CodingKey.swift"; sourceTree = ""; }; 0A11030B20864F94008ADD90 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Localizable.strings; sourceTree = ""; }; 0A11030C20864F9A008ADD90 /* es-MX */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "es-MX"; path = "es-MX.lproj/Localizable.strings"; sourceTree = ""; }; 30349BEF1FCCA78A00546A1E /* MVMCoreSessionTimeHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreSessionTimeHandler.h; sourceTree = ""; }; @@ -431,7 +429,6 @@ children = ( 946EE1AA237B5C940036751F /* Decoder.swift */, 946EE1B3237B619D0036751F /* Encoder.swift */, - 01F2A05323A83E9200D954D8 /* KeyedDecodingContainer+CodingKey.swift */, ); path = Extensions; sourceTree = ""; @@ -922,7 +919,6 @@ 01F2A05223A8325100D954D8 /* ModelMapping.swift in Sources */, AFBB969E1FBA3A9A0008D868 /* MVMCoreAlertObject.m in Sources */, 8876D5F51FB50AB000EB2E3D /* UILabel+MFCustom.m in Sources */, - 01F2A05423A83E9200D954D8 /* KeyedDecodingContainer+CodingKey.swift in Sources */, AFBB96B31FBA3B590008D868 /* MVMCoreGetterUtility.m in Sources */, AF43A7071FC4D7A2008E9347 /* MVMCoreObject.m in Sources */, D2DEDCB723C63F3B00C44CC4 /* Clamping.swift in Sources */, diff --git a/MVMCore/MVMCore/Models/Extensions/KeyedDecodingContainer+CodingKey.swift b/MVMCore/MVMCore/Models/Extensions/KeyedDecodingContainer+CodingKey.swift deleted file mode 100644 index e54ade6..0000000 --- a/MVMCore/MVMCore/Models/Extensions/KeyedDecodingContainer+CodingKey.swift +++ /dev/null @@ -1,34 +0,0 @@ -// -// KeyedDecodingContainer+Action.swift -// MVMCore -// -// Created by Suresh, Kamlesh on 12/16/19. -// Copyright © 2019 myverizon. All rights reserved. -// - -import Foundation - -extension KeyedDecodingContainer where Key : CodingKey { -// private enum TypeCodingKey: String, CodingKey { -// case type -// } - -// public func decode(codingKey: KeyedDecodingContainer.Key) throws -> ActionProtocol { -// return try decode(codingKey: codingKey, typeCodingKey: TypeCodingKey.type) -// } -// -// public func decodeActionIfPresent(codingKey: KeyedDecodingContainer.Key) throws -> ActionProtocol? { -// return try decodeIfPresent(codingKey: codingKey, typeCodingKey: TypeCodingKey.type) -// } -// -// public func decodeActionArray(codingKey: KeyedDecodingContainer.Key) throws -> [ActionProtocol] { -// guard let models = try decodeArray(codingKey: codingKey, typeCodingKey: TypeCodingKey.type) as? [ActionProtocol] else { -// throw ModelRegistry.Error.decoderError -// } -// return models -// } -// -// public func decodeActionArrayIfPresent(codingKey: KeyedDecodingContainer.Key) throws -> [ActionProtocol]? { -// return try decodeArrayIfPresent(codingKey: codingKey, typeCodingKey: TypeCodingKey.type) as? [ActionProtocol] -// } -} diff --git a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h index efa33b6..eb9fba9 100644 --- a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h +++ b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h @@ -9,7 +9,7 @@ #import #import "MVMCoreRequestParameters.h" -#define ENABLE_HARD_CODED_RESPONSE 1 && DEBUG +#define ENABLE_HARD_CODED_RESPONSE 0 && DEBUG #if ENABLE_HARD_CODED_RESPONSE From 6190a37336bfb98ff7e41b2e7915066129b31f86 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 21 Jan 2020 15:47:03 -0500 Subject: [PATCH 44/50] name change --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 64 +++++++++---------- ...ActionBack.swift => ActionBackModel.swift} | 2 +- ...ActionCall.swift => ActionCallModel.swift} | 4 +- ...otocol.swift => ActionModelProtocol.swift} | 4 +- ...OpenApp.swift => ActionOpenAppModel.swift} | 4 +- ...enPage.swift => ActionOpenPageModel.swift} | 2 +- ...OpenUrl.swift => ActionOpenUrlModel.swift} | 4 +- ...tionPopup.swift => ActionPopupModel.swift} | 4 +- ...pAlert.swift => ActionTopAlertModel.swift} | 4 +- .../KeyedDecodingContainer+CodingKey.swift | 12 ++-- MVMCore/MVMCore/Models/ModelMapping.swift | 14 ++-- 11 files changed, 59 insertions(+), 59 deletions(-) rename MVMCore/MVMCore/Models/ActionType/{ActionBack.swift => ActionBackModel.swift} (84%) rename MVMCore/MVMCore/Models/ActionType/{ActionCall.swift => ActionCallModel.swift} (83%) rename MVMCore/MVMCore/Models/ActionType/{ActionProtocol.swift => ActionModelProtocol.swift} (83%) rename MVMCore/MVMCore/Models/ActionType/{ActionOpenApp.swift => ActionOpenAppModel.swift} (81%) rename MVMCore/MVMCore/Models/ActionType/{ActionOpenPage.swift => ActionOpenPageModel.swift} (87%) rename MVMCore/MVMCore/Models/ActionType/{ActionOpenUrl.swift => ActionOpenUrlModel.swift} (82%) rename MVMCore/MVMCore/Models/ActionType/{ActionPopup.swift => ActionPopupModel.swift} (82%) rename MVMCore/MVMCore/Models/ActionType/{ActionTopAlert.swift => ActionTopAlertModel.swift} (81%) diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index 9fb4ce4..ca804ec 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -22,14 +22,14 @@ /* Begin PBXBuildFile section */ 01C851CF23CF7B260021F976 /* JSONMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01C851CE23CF7B260021F976 /* JSONMap.swift */; }; - 01C851D123CF97FE0021F976 /* ActionBack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01C851D023CF97FE0021F976 /* ActionBack.swift */; }; + 01C851D123CF97FE0021F976 /* ActionBackModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01C851D023CF97FE0021F976 /* ActionBackModel.swift */; }; 01DF561421F90ADC00CC099B /* Dictionary+MFConvenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF561321F90ADC00CC099B /* Dictionary+MFConvenience.swift */; }; - 01F2A03623A80A7300D954D8 /* ActionProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A03523A80A7300D954D8 /* ActionProtocol.swift */; }; - 01F2A03923A812DD00D954D8 /* ActionOpenUrl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A03823A812DD00D954D8 /* ActionOpenUrl.swift */; }; - 01F2A03B23A8159900D954D8 /* ActionOpenApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A03A23A8159900D954D8 /* ActionOpenApp.swift */; }; - 01F2A04C23A82B1B00D954D8 /* ActionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A04B23A82B1B00D954D8 /* ActionCall.swift */; }; - 01F2A04E23A82CF500D954D8 /* ActionPopup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A04D23A82CF500D954D8 /* ActionPopup.swift */; }; - 01F2A05023A82D0800D954D8 /* ActionTopAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A04F23A82D0800D954D8 /* ActionTopAlert.swift */; }; + 01F2A03623A80A7300D954D8 /* ActionModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A03523A80A7300D954D8 /* ActionModelProtocol.swift */; }; + 01F2A03923A812DD00D954D8 /* ActionOpenUrlModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A03823A812DD00D954D8 /* ActionOpenUrlModel.swift */; }; + 01F2A03B23A8159900D954D8 /* ActionOpenAppModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A03A23A8159900D954D8 /* ActionOpenAppModel.swift */; }; + 01F2A04C23A82B1B00D954D8 /* ActionCallModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A04B23A82B1B00D954D8 /* ActionCallModel.swift */; }; + 01F2A04E23A82CF500D954D8 /* ActionPopupModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A04D23A82CF500D954D8 /* ActionPopupModel.swift */; }; + 01F2A05023A82D0800D954D8 /* ActionTopAlertModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A04F23A82D0800D954D8 /* ActionTopAlertModel.swift */; }; 01F2A05223A8325100D954D8 /* ModelMapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A05123A8325100D954D8 /* ModelMapping.swift */; }; 01F2A05423A83E9200D954D8 /* KeyedDecodingContainer+CodingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A05323A83E9200D954D8 /* KeyedDecodingContainer+CodingKey.swift */; }; 30349BF11FCCA78A00546A1E /* MVMCoreSessionTimeHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 30349BEF1FCCA78A00546A1E /* MVMCoreSessionTimeHandler.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -55,7 +55,7 @@ 946EE1B0237B5EF70036751F /* JSONHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1AF237B5EF70036751F /* JSONHelper.swift */; }; 946EE1B2237B5F260036751F /* JSONValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1B1237B5F260036751F /* JSONValue.swift */; }; 946EE1B4237B619D0036751F /* Encoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1B3237B619D0036751F /* Encoder.swift */; }; - 946EE1BC237B691A0036751F /* ActionOpenPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1BB237B691A0036751F /* ActionOpenPage.swift */; }; + 946EE1BC237B691A0036751F /* ActionOpenPageModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1BB237B691A0036751F /* ActionOpenPageModel.swift */; }; A332F33F20C7231700DCD9D9 /* MVMCoreViewControllerAnimatedTransitioning.h in Headers */ = {isa = PBXBuildFile; fileRef = A332F33E20C7231600DCD9D9 /* MVMCoreViewControllerAnimatedTransitioning.h */; settings = {ATTRIBUTES = (Public, ); }; }; AF1201832108C9B400E2F592 /* MVMCoreViewManagerViewControllerProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = AF1201812108C9B400E2F592 /* MVMCoreViewManagerViewControllerProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; AF26DDAE1FCE6A37004E8F65 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = AF26DDB01FCE6A37004E8F65 /* Localizable.strings */; }; @@ -167,14 +167,14 @@ /* Begin PBXFileReference section */ 01C851CE23CF7B260021F976 /* JSONMap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONMap.swift; sourceTree = ""; }; - 01C851D023CF97FE0021F976 /* ActionBack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionBack.swift; sourceTree = ""; }; + 01C851D023CF97FE0021F976 /* ActionBackModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionBackModel.swift; sourceTree = ""; }; 01DF561321F90ADC00CC099B /* Dictionary+MFConvenience.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Dictionary+MFConvenience.swift"; sourceTree = ""; }; - 01F2A03523A80A7300D954D8 /* ActionProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionProtocol.swift; sourceTree = ""; }; - 01F2A03823A812DD00D954D8 /* ActionOpenUrl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionOpenUrl.swift; sourceTree = ""; }; - 01F2A03A23A8159900D954D8 /* ActionOpenApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionOpenApp.swift; sourceTree = ""; }; - 01F2A04B23A82B1B00D954D8 /* ActionCall.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionCall.swift; sourceTree = ""; }; - 01F2A04D23A82CF500D954D8 /* ActionPopup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionPopup.swift; sourceTree = ""; }; - 01F2A04F23A82D0800D954D8 /* ActionTopAlert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionTopAlert.swift; sourceTree = ""; }; + 01F2A03523A80A7300D954D8 /* ActionModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionModelProtocol.swift; sourceTree = ""; }; + 01F2A03823A812DD00D954D8 /* ActionOpenUrlModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionOpenUrlModel.swift; sourceTree = ""; }; + 01F2A03A23A8159900D954D8 /* ActionOpenAppModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionOpenAppModel.swift; sourceTree = ""; }; + 01F2A04B23A82B1B00D954D8 /* ActionCallModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionCallModel.swift; sourceTree = ""; }; + 01F2A04D23A82CF500D954D8 /* ActionPopupModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionPopupModel.swift; sourceTree = ""; }; + 01F2A04F23A82D0800D954D8 /* ActionTopAlertModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionTopAlertModel.swift; sourceTree = ""; }; 01F2A05123A8325100D954D8 /* ModelMapping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelMapping.swift; sourceTree = ""; }; 01F2A05323A83E9200D954D8 /* KeyedDecodingContainer+CodingKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "KeyedDecodingContainer+CodingKey.swift"; sourceTree = ""; }; 0A11030B20864F94008ADD90 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Localizable.strings; sourceTree = ""; }; @@ -204,7 +204,7 @@ 946EE1AF237B5EF70036751F /* JSONHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONHelper.swift; sourceTree = ""; }; 946EE1B1237B5F260036751F /* JSONValue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONValue.swift; sourceTree = ""; }; 946EE1B3237B619D0036751F /* Encoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Encoder.swift; sourceTree = ""; }; - 946EE1BB237B691A0036751F /* ActionOpenPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionOpenPage.swift; sourceTree = ""; }; + 946EE1BB237B691A0036751F /* ActionOpenPageModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionOpenPageModel.swift; sourceTree = ""; }; A332F33E20C7231600DCD9D9 /* MVMCoreViewControllerAnimatedTransitioning.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreViewControllerAnimatedTransitioning.h; sourceTree = ""; }; AF1201812108C9B400E2F592 /* MVMCoreViewManagerViewControllerProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreViewManagerViewControllerProtocol.h; sourceTree = ""; }; AF26DDAF1FCE6A37004E8F65 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = ""; }; @@ -449,14 +449,14 @@ 946EE1B6237B66630036751F /* ActionType */ = { isa = PBXGroup; children = ( - 01F2A03523A80A7300D954D8 /* ActionProtocol.swift */, - 946EE1BB237B691A0036751F /* ActionOpenPage.swift */, - 01F2A03823A812DD00D954D8 /* ActionOpenUrl.swift */, - 01F2A03A23A8159900D954D8 /* ActionOpenApp.swift */, - 01F2A04B23A82B1B00D954D8 /* ActionCall.swift */, - 01F2A04D23A82CF500D954D8 /* ActionPopup.swift */, - 01F2A04F23A82D0800D954D8 /* ActionTopAlert.swift */, - 01C851D023CF97FE0021F976 /* ActionBack.swift */, + 01F2A03523A80A7300D954D8 /* ActionModelProtocol.swift */, + 946EE1BB237B691A0036751F /* ActionOpenPageModel.swift */, + 01F2A03823A812DD00D954D8 /* ActionOpenUrlModel.swift */, + 01F2A03A23A8159900D954D8 /* ActionOpenAppModel.swift */, + 01F2A04B23A82B1B00D954D8 /* ActionCallModel.swift */, + 01F2A04D23A82CF500D954D8 /* ActionPopupModel.swift */, + 01F2A04F23A82D0800D954D8 /* ActionTopAlertModel.swift */, + 01C851D023CF97FE0021F976 /* ActionBackModel.swift */, ); path = ActionType; sourceTree = ""; @@ -880,12 +880,12 @@ AFFCFA671FCCC0D700FD0730 /* MVMCoreLoadingOverlayHandler.m in Sources */, AFBB968E1FBA3A9A0008D868 /* MVMCoreNavigationHandler.m in Sources */, D2E1FAD92260C3E400AEFD8C /* DelegateObject.swift in Sources */, - 01F2A03623A80A7300D954D8 /* ActionProtocol.swift in Sources */, + 01F2A03623A80A7300D954D8 /* ActionModelProtocol.swift in Sources */, AFBB96991FBA3A9A0008D868 /* MVMCoreAlertController.m in Sources */, 881D26941FCC9D180079C521 /* MVMCoreOperation.m in Sources */, AFED77A41FCCA29400BAE689 /* MVMCoreViewControllerMappingObject.m in Sources */, 01C851CF23CF7B260021F976 /* JSONMap.swift in Sources */, - 01F2A04C23A82B1B00D954D8 /* ActionCall.swift in Sources */, + 01F2A04C23A82B1B00D954D8 /* ActionCallModel.swift in Sources */, 8876D5ED1FB50AB000EB2E3D /* NSDictionary+MFConvenience.m in Sources */, AFBB968C1FBA3A9A0008D868 /* MVMCoreDismissViewControllerOperation.m in Sources */, AFBB96BA1FBA3CEC0008D868 /* MVMCoreActionHandler.m in Sources */, @@ -895,7 +895,7 @@ AFBB965F1FBA3A570008D868 /* MFFreebeeOperation.m in Sources */, AFBB96901FBA3A9A0008D868 /* MVMCoreNavigationObject.m in Sources */, 946EE1AB237B5C940036751F /* Decoder.swift in Sources */, - 946EE1BC237B691A0036751F /* ActionOpenPage.swift in Sources */, + 946EE1BC237B691A0036751F /* ActionOpenPageModel.swift in Sources */, AFBB96A61FBA3A9A0008D868 /* MVMCoreTopAlertOperation.m in Sources */, 881D26931FCC9D180079C521 /* MVMCoreErrorObject.m in Sources */, 946EE1B0237B5EF70036751F /* JSONHelper.swift in Sources */, @@ -905,13 +905,13 @@ 946EE1B2237B5F260036751F /* JSONValue.swift in Sources */, AFBB96971FBA3A9A0008D868 /* MVMCorePresentViewControllerOperation.m in Sources */, AFBB96581FBA3A570008D868 /* FreeBeeAuthObject.m in Sources */, - 01F2A04E23A82CF500D954D8 /* ActionPopup.swift in Sources */, + 01F2A04E23A82CF500D954D8 /* ActionPopupModel.swift in Sources */, AF43A5781FBA5B7C008E9347 /* MVMCoreJSONConstants.m in Sources */, AFBB96691FBA3A570008D868 /* MVMCoreRequestParameters.m in Sources */, AFED77A31FCCA29400BAE689 /* MVMCoreViewControllerNibMappingObject.m in Sources */, 8876D5EB1FB50AB000EB2E3D /* NSDecimalNumber+MFConvenience.m in Sources */, AFBB96A41FBA3A9A0008D868 /* MVMCoreTopAlertObject.m in Sources */, - 01F2A03923A812DD00D954D8 /* ActionOpenUrl.swift in Sources */, + 01F2A03923A812DD00D954D8 /* ActionOpenUrlModel.swift in Sources */, AFBB96351FBA34310008D868 /* MVMCoreErrorConstants.m in Sources */, AFBB969C1FBA3A9A0008D868 /* MVMCoreAlertHandler.m in Sources */, AF43A5881FBB67D6008E9347 /* MVMCoreActionUtility.m in Sources */, @@ -929,13 +929,13 @@ 01DF561421F90ADC00CC099B /* Dictionary+MFConvenience.swift in Sources */, AFBB96B11FBA3B590008D868 /* MVMCoreDispatchUtility.m in Sources */, 946EE1A3237B59C30036751F /* Model.swift in Sources */, - 01F2A05023A82D0800D954D8 /* ActionTopAlert.swift in Sources */, + 01F2A05023A82D0800D954D8 /* ActionTopAlertModel.swift in Sources */, AFBB965B1FBA3A570008D868 /* FreeBeeUrlObject.m in Sources */, AFEA17A9209B6A1C00BC6740 /* MVMCoreBlockOperation.m in Sources */, AF43A70A1FC4F415008E9347 /* MVMCoreCache.m in Sources */, AF43A6FF1FBE3252008E9347 /* Reachability.m in Sources */, - 01C851D123CF97FE0021F976 /* ActionBack.swift in Sources */, - 01F2A03B23A8159900D954D8 /* ActionOpenApp.swift in Sources */, + 01C851D123CF97FE0021F976 /* ActionBackModel.swift in Sources */, + 01F2A03B23A8159900D954D8 /* ActionOpenAppModel.swift in Sources */, AFBB96921FBA3A9A0008D868 /* MVMCoreNavigationOperation.m in Sources */, AFBB96611FBA3A570008D868 /* MVMCoreLoadObject.m in Sources */, 946EE1B4237B619D0036751F /* Encoder.swift in Sources */, diff --git a/MVMCore/MVMCore/Models/ActionType/ActionBack.swift b/MVMCore/MVMCore/Models/ActionType/ActionBackModel.swift similarity index 84% rename from MVMCore/MVMCore/Models/ActionType/ActionBack.swift rename to MVMCore/MVMCore/Models/ActionType/ActionBackModel.swift index 4c93f94..0080e38 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionBack.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionBackModel.swift @@ -8,7 +8,7 @@ import Foundation -@objcMembers public class ActionBack: ActionProtocol { +@objcMembers public class ActionBackModel: ActionModelProtocol { public static var identifier: String = "back" public var actionType: String? public var extraParameters: JSONValueDictionary? diff --git a/MVMCore/MVMCore/Models/ActionType/ActionCall.swift b/MVMCore/MVMCore/Models/ActionType/ActionCallModel.swift similarity index 83% rename from MVMCore/MVMCore/Models/ActionType/ActionCall.swift rename to MVMCore/MVMCore/Models/ActionType/ActionCallModel.swift index 198ab37..71f99ad 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionCall.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionCallModel.swift @@ -1,5 +1,5 @@ // -// ActionCall.swift +// ActionCallModel.swift // MVMCore // // Created by Suresh, Kamlesh on 12/16/19. @@ -8,7 +8,7 @@ import Foundation -@objcMembers public class ActionCall: ActionProtocol { +@objcMembers public class ActionCallModel: ActionModelProtocol { public static var identifier: String = "call" public var actionType: String? public var callNumber: String diff --git a/MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift b/MVMCore/MVMCore/Models/ActionType/ActionModelProtocol.swift similarity index 83% rename from MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift rename to MVMCore/MVMCore/Models/ActionType/ActionModelProtocol.swift index c6aeb72..a610bfd 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionProtocol.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionModelProtocol.swift @@ -1,5 +1,5 @@ // -// ActionProtocol.swift +// ActionModelProtocol.swift // MVMCore // // Created by Suresh, Kamlesh on 12/16/19. @@ -12,7 +12,7 @@ public enum ActionCodingKey: String, CodingKey { case actionType } -public protocol ActionProtocol: Model { +public protocol ActionModelProtocol: Model { var actionType: String? { get set } var extraParameters: JSONValueDictionary? { get set } var analyticsData: JSONValueDictionary? { get set } diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenApp.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenAppModel.swift similarity index 81% rename from MVMCore/MVMCore/Models/ActionType/ActionOpenApp.swift rename to MVMCore/MVMCore/Models/ActionType/ActionOpenAppModel.swift index 0a2d838..832d490 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenApp.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenAppModel.swift @@ -1,5 +1,5 @@ // -// ActionOpenApp.swift +// ActionOpenAppModel.swift // MVMCore // // Created by Suresh, Kamlesh on 12/16/19. @@ -8,7 +8,7 @@ import Foundation -@objcMembers public class ActionOpenApp: ActionProtocol { +@objcMembers public class ActionOpenAppModel: ActionModelProtocol { public static var identifier: String = "openApp" public var actionType: String? public var appURL: String diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenPage.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenPageModel.swift similarity index 87% rename from MVMCore/MVMCore/Models/ActionType/ActionOpenPage.swift rename to MVMCore/MVMCore/Models/ActionType/ActionOpenPageModel.swift index b78de5a..9e6c986 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenPage.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenPageModel.swift @@ -8,7 +8,7 @@ import Foundation -@objcMembers public class ActionOpenPage: ActionProtocol { +@objcMembers public class ActionOpenPageModel: ActionModelProtocol { public static var identifier: String = "openPage" public var actionType: String? public var pageType: String diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift similarity index 82% rename from MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift rename to MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift index af9871a..299e42a 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrl.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift @@ -1,5 +1,5 @@ // -// ActionOpenUrl.swift +// ActionOpenUrlModel.swift // MVMCore // // Created by Suresh, Kamlesh on 12/16/19. @@ -8,7 +8,7 @@ import Foundation -@objcMembers public class ActionOpenUrl: ActionProtocol { +@objcMembers public class ActionOpenUrlModel: ActionModelProtocol { public static var identifier: String = "openURL" public var actionType: String? public var browserUrl: String diff --git a/MVMCore/MVMCore/Models/ActionType/ActionPopup.swift b/MVMCore/MVMCore/Models/ActionType/ActionPopupModel.swift similarity index 82% rename from MVMCore/MVMCore/Models/ActionType/ActionPopup.swift rename to MVMCore/MVMCore/Models/ActionType/ActionPopupModel.swift index 83bde62..2e33337 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionPopup.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionPopupModel.swift @@ -1,5 +1,5 @@ // -// ActionPopup.swift +// ActionPopupModel.swift // MVMCore // // Created by Suresh, Kamlesh on 12/16/19. @@ -8,7 +8,7 @@ import Foundation -@objcMembers public class ActionPopup: ActionProtocol { +@objcMembers public class ActionPopupModel: ActionModelProtocol { public static var identifier: String = "popup" public var actionType: String? public var pageType: String diff --git a/MVMCore/MVMCore/Models/ActionType/ActionTopAlert.swift b/MVMCore/MVMCore/Models/ActionType/ActionTopAlertModel.swift similarity index 81% rename from MVMCore/MVMCore/Models/ActionType/ActionTopAlert.swift rename to MVMCore/MVMCore/Models/ActionType/ActionTopAlertModel.swift index cbd2fbd..89b7015 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionTopAlert.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionTopAlertModel.swift @@ -1,5 +1,5 @@ // -// ActionTopAlert.swift +// ActionTopAlertModel.swift // MVMCore // // Created by Suresh, Kamlesh on 12/16/19. @@ -8,7 +8,7 @@ import Foundation -@objcMembers public class ActionTopAlert: ActionProtocol { +@objcMembers public class ActionTopAlertModel: ActionModelProtocol { public static var identifier: String = "topAlert" public var actionType: String? public var pageType: String diff --git a/MVMCore/MVMCore/Models/Extensions/KeyedDecodingContainer+CodingKey.swift b/MVMCore/MVMCore/Models/Extensions/KeyedDecodingContainer+CodingKey.swift index e54ade6..25917a5 100644 --- a/MVMCore/MVMCore/Models/Extensions/KeyedDecodingContainer+CodingKey.swift +++ b/MVMCore/MVMCore/Models/Extensions/KeyedDecodingContainer+CodingKey.swift @@ -13,22 +13,22 @@ extension KeyedDecodingContainer where Key : CodingKey { // case type // } -// public func decode(codingKey: KeyedDecodingContainer.Key) throws -> ActionProtocol { +// public func decode(codingKey: KeyedDecodingContainer.Key) throws -> ActionModelProtocol { // return try decode(codingKey: codingKey, typeCodingKey: TypeCodingKey.type) // } // -// public func decodeActionIfPresent(codingKey: KeyedDecodingContainer.Key) throws -> ActionProtocol? { +// public func decodeActionIfPresent(codingKey: KeyedDecodingContainer.Key) throws -> ActionModelProtocol? { // return try decodeIfPresent(codingKey: codingKey, typeCodingKey: TypeCodingKey.type) // } // -// public func decodeActionArray(codingKey: KeyedDecodingContainer.Key) throws -> [ActionProtocol] { -// guard let models = try decodeArray(codingKey: codingKey, typeCodingKey: TypeCodingKey.type) as? [ActionProtocol] else { +// public func decodeActionArray(codingKey: KeyedDecodingContainer.Key) throws -> [ActionModelProtocol] { +// guard let models = try decodeArray(codingKey: codingKey, typeCodingKey: TypeCodingKey.type) as? [ActionModelProtocol] else { // throw ModelRegistry.Error.decoderError // } // return models // } // -// public func decodeActionArrayIfPresent(codingKey: KeyedDecodingContainer.Key) throws -> [ActionProtocol]? { -// return try decodeArrayIfPresent(codingKey: codingKey, typeCodingKey: TypeCodingKey.type) as? [ActionProtocol] +// public func decodeActionArrayIfPresent(codingKey: KeyedDecodingContainer.Key) throws -> [ActionModelProtocol]? { +// return try decodeArrayIfPresent(codingKey: codingKey, typeCodingKey: TypeCodingKey.type) as? [ActionModelProtocol] // } } diff --git a/MVMCore/MVMCore/Models/ModelMapping.swift b/MVMCore/MVMCore/Models/ModelMapping.swift index 26d5ddc..383e98e 100644 --- a/MVMCore/MVMCore/Models/ModelMapping.swift +++ b/MVMCore/MVMCore/Models/ModelMapping.swift @@ -10,12 +10,12 @@ import Foundation @objcMembers public class ModelMapping: NSObject { public static func registerObjects() { - ModelRegistry.register(ActionOpenPage.self) - ModelRegistry.register(ActionOpenUrl.self) - ModelRegistry.register(ActionOpenApp.self) - ModelRegistry.register(ActionCall.self) - ModelRegistry.register(ActionPopup.self) - ModelRegistry.register(ActionTopAlert.self) - ModelRegistry.register(ActionBack.self) + ModelRegistry.register(ActionOpenPageModel.self) + ModelRegistry.register(ActionOpenUrlModel.self) + ModelRegistry.register(ActionOpenAppModel.self) + ModelRegistry.register(ActionCallModel.self) + ModelRegistry.register(ActionPopupModel.self) + ModelRegistry.register(ActionTopAlertModel.self) + ModelRegistry.register(ActionBackModel.self) } } From f86c6fd5d2985a5c0ab884d9d6d108973e201e10 Mon Sep 17 00:00:00 2001 From: "Chintakrinda, Arun Kumar (Arun)" Date: Thu, 23 Jan 2020 17:02:25 +0530 Subject: [PATCH 45/50] Missing properties added for openURL --- .../MVMCore/Models/ActionType/ActionOpenUrlModel.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift index 1316d6a..52acd33 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift @@ -16,8 +16,16 @@ import Foundation public var analyticsData: JSONValueDictionary? // Temporary fix till server changes public var title: String? + + //Missing params + public var openOauthWebView: Bool? + public var showNativeNavigation: Bool? + public var openInWebview: Bool? - public init(browserUrl: String) { + public init(browserUrl: String, openOauthWebView: Bool?, showNativeNavigation: Bool?, openInWebview: Bool?) { self.browserUrl = browserUrl + self.openOauthWebView = openOauthWebView ?? false + self.showNativeNavigation = showNativeNavigation ?? false + self.openInWebview = openInWebview ?? false } } From 79b894e58201865c5b554053bdd8dbc9f57b03b0 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 23 Jan 2020 10:37:09 -0500 Subject: [PATCH 46/50] remove optional property from init --- MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift | 5 +---- .../HardCodedServerResponse/MFHardCodedServerResponse.h | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift index 52acd33..7b384eb 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift @@ -22,10 +22,7 @@ import Foundation public var showNativeNavigation: Bool? public var openInWebview: Bool? - public init(browserUrl: String, openOauthWebView: Bool?, showNativeNavigation: Bool?, openInWebview: Bool?) { + public init(browserUrl: String) { self.browserUrl = browserUrl - self.openOauthWebView = openOauthWebView ?? false - self.showNativeNavigation = showNativeNavigation ?? false - self.openInWebview = openInWebview ?? false } } diff --git a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h index eb9fba9..efa33b6 100644 --- a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h +++ b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h @@ -9,7 +9,7 @@ #import #import "MVMCoreRequestParameters.h" -#define ENABLE_HARD_CODED_RESPONSE 0 && DEBUG +#define ENABLE_HARD_CODED_RESPONSE 1 && DEBUG #if ENABLE_HARD_CODED_RESPONSE From 1da5034dc6c0925e665cea123fa0cc1753edb7ed Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 23 Jan 2020 10:39:09 -0500 Subject: [PATCH 47/50] comments --- MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift | 2 ++ .../Utility/HardCodedServerResponse/MFHardCodedServerResponse.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift index 7b384eb..09299e6 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift @@ -17,6 +17,8 @@ import Foundation // Temporary fix till server changes public var title: String? + + //TODO: Should be removed in future releases. This should be MF specific. //Missing params public var openOauthWebView: Bool? public var showNativeNavigation: Bool? diff --git a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h index efa33b6..eb9fba9 100644 --- a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h +++ b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h @@ -9,7 +9,7 @@ #import #import "MVMCoreRequestParameters.h" -#define ENABLE_HARD_CODED_RESPONSE 1 && DEBUG +#define ENABLE_HARD_CODED_RESPONSE 0 && DEBUG #if ENABLE_HARD_CODED_RESPONSE From 3db60ff26bd04a887eac90bb1bee6b09cf04d56f Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 23 Jan 2020 14:46:32 -0500 Subject: [PATCH 48/50] fixes --- .../Utility/HardCodedServerResponse/MFHardCodedServerResponse.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h index eb9fba9..efa33b6 100644 --- a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h +++ b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h @@ -9,7 +9,7 @@ #import #import "MVMCoreRequestParameters.h" -#define ENABLE_HARD_CODED_RESPONSE 0 && DEBUG +#define ENABLE_HARD_CODED_RESPONSE 1 && DEBUG #if ENABLE_HARD_CODED_RESPONSE From e661ff8079d9829572381e42b7ffeac869f4299f Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 23 Jan 2020 14:47:41 -0500 Subject: [PATCH 49/50] back to 0 --- .../Utility/HardCodedServerResponse/MFHardCodedServerResponse.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h index efa33b6..eb9fba9 100644 --- a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h +++ b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h @@ -9,7 +9,7 @@ #import #import "MVMCoreRequestParameters.h" -#define ENABLE_HARD_CODED_RESPONSE 1 && DEBUG +#define ENABLE_HARD_CODED_RESPONSE 0 && DEBUG #if ENABLE_HARD_CODED_RESPONSE From 7b50474d270485b72d300b2a24d450421b590027 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 23 Jan 2020 17:05:18 -0500 Subject: [PATCH 50/50] logs --- MVMCore/MVMCore/Models/Model/ModelRegistry.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index 04a8f78..c92727f 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -36,12 +36,14 @@ extension KeyedDecodingContainer where Key: CodingKey { /// Decodes to a registered model based on the identifier public func decodeModel(codingKey: KeyedDecodingContainer.Key, typeCodingKey: TypeKey) throws -> M { guard let model: Model = try decodeModelIfPresent(codingKey: codingKey, typeCodingKey: typeCodingKey) else { + MVMCoreLoggingHandler.logDebugMessage(withDelegate: "ModelRegistry Error decoderErrorObjectNotPresent: \(codingKey)") throw ModelRegistry.Error.decoderErrorObjectNotPresent } if let model = model as? M { return model } else { + MVMCoreLoggingHandler.logDebugMessage(withDelegate: "ModelRegistry Error decoderError: \(codingKey)") throw ModelRegistry.Error.decoderError } } @@ -68,6 +70,7 @@ extension KeyedDecodingContainer where Key: CodingKey { if let model = model as? M { return model } else { + MVMCoreLoggingHandler.logDebugMessage(withDelegate: "ModelRegistry Error decoderError: \(codingKey)") throw ModelRegistry.Error.decoderError } } @@ -84,6 +87,7 @@ extension KeyedDecodingContainer where Key: CodingKey { /// Decodes an array of registered model based on the identifiers. public func decodeModels(codingKey: KeyedDecodingContainer.Key, typeCodingKey: TypeKey) throws -> [Model] { guard let models: [Model] = try decodeModelsIfPresent(codingKey: codingKey, typeCodingKey: typeCodingKey) else { + MVMCoreLoggingHandler.logDebugMessage(withDelegate: "ModelRegistry Error decoderErrorObjectNotPresent: \(codingKey)") throw ModelRegistry.Error.decoderErrorObjectNotPresent } return models @@ -101,6 +105,7 @@ extension KeyedDecodingContainer where Key: CodingKey { /// Decodes an array with arrays of models based on the identifiers. public func decodeModels2D(codingKey: KeyedDecodingContainer.Key, typeCodingKey: TypeKey) throws -> [[Model]] { guard let models: [[Model]] = try decodeModels2DIfPresent(codingKey: codingKey, typeCodingKey: typeCodingKey) else { + MVMCoreLoggingHandler.logDebugMessage(withDelegate: "ModelRegistry Error decoderErrorObjectNotPresent: \(codingKey)") throw ModelRegistry.Error.decoderErrorObjectNotPresent } return models @@ -160,6 +165,7 @@ extension UnkeyedDecodingContainer { if let identifier = try nestedContainer.decodeIfPresent(String.self, forKey: typeCodingKey) { //get the type guard let type = ModelRegistry.getType(for: identifier) else { + MVMCoreLoggingHandler.logDebugMessage(withDelegate: "ModelRegistry Error decoderErrorModelNotMapped: \(identifier)") throw ModelRegistry.Error.decoderErrorModelNotMapped } //now get the decoder to use for the type @@ -178,6 +184,7 @@ extension UnkeyedDecodingContainer { while !containerCopy.isAtEnd { var arraycontainerCopy = try containerCopy.nestedUnkeyedContainer() guard let models = try arraycontainerCopy.decodeModelsIfPresent(typeCodingKey: typeCodingKey) else { + MVMCoreLoggingHandler.logDebugMessage(withDelegate: "ModelRegistry Error decoderErrorModelNotMapped: \(typeCodingKey)") throw ModelRegistry.Error.decoderErrorModelNotMapped } modelLists.append(models)