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)