Merge branch 'feature/coding_action_map' into feature/coding

This commit is contained in:
Pfeil, Scott Robert 2020-01-13 12:28:04 -05:00
commit 54a598344f
15 changed files with 327 additions and 46 deletions

View File

@ -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 */; };
@ -151,11 +159,20 @@
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 */
/* Begin PBXFileReference section */
01DF561321F90ADC00CC099B /* Dictionary+MFConvenience.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Dictionary+MFConvenience.swift"; sourceTree = "<group>"; };
01F2A03523A80A7300D954D8 /* ActionProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionProtocol.swift; sourceTree = "<group>"; };
01F2A03823A812DD00D954D8 /* ActionOpenUrl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionOpenUrl.swift; sourceTree = "<group>"; };
01F2A03A23A8159900D954D8 /* ActionOpenApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionOpenApp.swift; sourceTree = "<group>"; };
01F2A04B23A82B1B00D954D8 /* ActionCall.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionCall.swift; sourceTree = "<group>"; };
01F2A04D23A82CF500D954D8 /* ActionPopup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionPopup.swift; sourceTree = "<group>"; };
01F2A04F23A82D0800D954D8 /* ActionTopAlert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionTopAlert.swift; sourceTree = "<group>"; };
01F2A05123A8325100D954D8 /* ModelMapping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelMapping.swift; sourceTree = "<group>"; };
01F2A05323A83E9200D954D8 /* KeyedDecodingContainer+CodingKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "KeyedDecodingContainer+CodingKey.swift"; sourceTree = "<group>"; };
0A11030B20864F94008ADD90 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Localizable.strings; sourceTree = "<group>"; };
0A11030C20864F9A008ADD90 /* es-MX */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "es-MX"; path = "es-MX.lproj/Localizable.strings"; sourceTree = "<group>"; };
30349BEF1FCCA78A00546A1E /* MVMCoreSessionTimeHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreSessionTimeHandler.h; sourceTree = "<group>"; };
@ -183,7 +200,7 @@
946EE1AF237B5EF70036751F /* JSONHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONHelper.swift; sourceTree = "<group>"; };
946EE1B1237B5F260036751F /* JSONValue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONValue.swift; sourceTree = "<group>"; };
946EE1B3237B619D0036751F /* Encoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Encoder.swift; sourceTree = "<group>"; };
946EE1BB237B691A0036751F /* ActionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionModel.swift; sourceTree = "<group>"; };
946EE1BB237B691A0036751F /* ActionOpenPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionOpenPage.swift; sourceTree = "<group>"; };
A332F33E20C7231600DCD9D9 /* MVMCoreViewControllerAnimatedTransitioning.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreViewControllerAnimatedTransitioning.h; sourceTree = "<group>"; };
AF1201812108C9B400E2F592 /* MVMCoreViewManagerViewControllerProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreViewManagerViewControllerProtocol.h; sourceTree = "<group>"; };
AF26DDAF1FCE6A37004E8F65 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
@ -293,6 +310,7 @@
D282AAB72240342D00C46919 /* NSNumber+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSNumber+Extension.swift"; sourceTree = "<group>"; };
D2DEDCB623C63F3B00C44CC4 /* Clamping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Clamping.swift; sourceTree = "<group>"; };
D2DEDCB823C6400600C44CC4 /* UnitInterval.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnitInterval.swift; sourceTree = "<group>"; };
D2DEDCBA23C65BC300C44CC4 /* Percent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Percent.swift; sourceTree = "<group>"; };
D2E1FAD82260C3E400AEFD8C /* DelegateObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DelegateObject.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
@ -386,6 +404,7 @@
946EE19B237B4DB80036751F /* Models */ = {
isa = PBXGroup;
children = (
01F2A05123A8325100D954D8 /* ModelMapping.swift */,
946EE1B6237B66630036751F /* ActionType */,
946EE1A9237B5C720036751F /* Extensions */,
946EE1A8237B5C650036751F /* Model */,
@ -408,6 +427,7 @@
children = (
946EE1AA237B5C940036751F /* Decoder.swift */,
946EE1B3237B619D0036751F /* Encoder.swift */,
01F2A05323A83E9200D954D8 /* KeyedDecodingContainer+CodingKey.swift */,
);
path = Extensions;
sourceTree = "<group>";
@ -424,7 +444,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 = "<group>";
@ -664,6 +690,7 @@
children = (
D2DEDCB623C63F3B00C44CC4 /* Clamping.swift */,
D2DEDCB823C6400600C44CC4 /* UnitInterval.swift */,
D2DEDCBA23C65BC300C44CC4 /* Percent.swift */,
);
path = PropertyWrappers;
sourceTree = "<group>";
@ -847,9 +874,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 */,
@ -859,7 +888,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 */,
@ -869,11 +898,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 */,
@ -881,23 +912,28 @@
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 */,
D2DEDCB723C63F3B00C44CC4 /* Clamping.swift 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 */,
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 */,

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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 }
}
}

View File

@ -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
}
}

View File

@ -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<K>.Key) throws -> ActionProtocol {
// return try decode(codingKey: codingKey, typeCodingKey: TypeCodingKey.type)
// }
//
// public func decodeActionIfPresent(codingKey: KeyedDecodingContainer<K>.Key) throws -> ActionProtocol? {
// return try decodeIfPresent(codingKey: codingKey, typeCodingKey: TypeCodingKey.type)
// }
//
// public func decodeActionArray(codingKey: KeyedDecodingContainer<K>.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<K>.Key) throws -> [ActionProtocol]? {
// return try decodeArrayIfPresent(codingKey: codingKey, typeCodingKey: TypeCodingKey.type) as? [ActionProtocol]
// }
}

View File

@ -1,3 +1,4 @@
//
// ModelRegistry.swift
// MVMCore
@ -16,9 +17,9 @@ public struct ModelRegistry {
case decoderErrorObjectNotPresent
case decoderErrorModelNotMapped
}
fileprivate static var types = [String: Model.Type]()
/// Register the model.
public static func register<M: Model>(_ type: M.Type) {
types[M.identifier] = type
@ -58,7 +59,7 @@ extension KeyedDecodingContainer where Key: CodingKey {
MVMCoreLoggingHandler.logDebugMessage(withDelegate: "Model not mapped: \(identifier)")
throw ModelRegistry.Error.decoderErrorModelNotMapped
}
//decode the type using the decoder
let model = try type.decode(keyedContainer: self, codingKey: codingKey)
@ -74,24 +75,9 @@ 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.
public func decodeModels<TypeKey: CodingKey>(codingKey: KeyedDecodingContainer<K>.Key, typeCodingKey: TypeKey) throws -> [Model] {
guard let models: [Model] = try decodeModelsIfPresent(codingKey: codingKey, typeCodingKey: typeCodingKey) else {
@ -99,10 +85,26 @@ extension KeyedDecodingContainer where Key: CodingKey {
}
return models
}
/// Decodes an array with arrays of models based on the identifiers, optional.
public func decodeModels2DIfPresent<TypeKey: CodingKey>(codingKey: KeyedDecodingContainer<K>.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<TypeKey: CodingKey>(codingKey: KeyedDecodingContainer<K>.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 {
/// Encodes a model, optional.
public mutating func encodeModelIfPresent(_ value: Model?, forKey key: KeyedEncodingContainer<K>.Key) throws {
if let value = value {
@ -110,18 +112,18 @@ extension KeyedEncodingContainer where Key: CodingKey {
try value.encode(to: encoder)
}
}
/// Encodes a model.
public mutating func encodeModel(_ value: Model, forKey key: KeyedEncodingContainer<K>.Key) throws {
let encoder = self.superEncoder(forKey: key)
try value.encode(to: encoder)
}
/// Encodes an array of models
public mutating func encodeModels(_ list: [Model], forKey key:KeyedEncodingContainer<K>.Key) throws {
try encodeModelsIfPresent(list, forKey: key)
}
/// Encodes an array of models, optional, need instance type as input paramaeter list
public mutating func encodeModelsIfPresent(_ list: [Model]?, forKey key:KeyedEncodingContainer<K>.Key) throws {
guard let list = list else { return }
@ -130,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<K>.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<TypeKey: CodingKey>(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<TypeKey: CodingKey>(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
}
}

View File

@ -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)
}
}

View File

@ -9,6 +9,7 @@
#import "MVMCoreSessionObject.h"
#import "MVMCoreObject.h"
#import "MVMCoreActionUtility.h"
#import <MVMCore/MVMCore-Swift.h>
@implementation MVMCoreSessionObject
@ -20,6 +21,7 @@
}
+ (nullable instancetype)sharedGlobal {
[ModelMapping registerObjects];
return [MVMCoreActionUtility initializerClassCheck:[MVMCoreObject sharedInstance].session classToVerify:self];
}

View File

@ -14,7 +14,7 @@ public struct Clamping<Value: Comparable> {
private var value: Value
private let range: ClosedRange<Value>
init(range: ClosedRange<Value>) {
public init(range: ClosedRange<Value>) {
self.value = range.lowerBound
self.range = range
}

View File

@ -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)
}
}