From 5f395f8cc37138120504fb6381e34fb8df0f115b Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 18 Dec 2019 12:09:22 -0500 Subject: [PATCH 1/4] 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 74f7826e4be4d466bff0515aa6c36876468b7d1f Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 8 Jan 2020 13:22:47 -0500 Subject: [PATCH 2/4] 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 3/4] 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 4/4] 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 + } }