actionType fix

This commit is contained in:
Pfeil, Scott Robert 2020-01-14 10:13:21 -05:00
parent 148e556ddb
commit 03f387487f
2 changed files with 10 additions and 6 deletions

View File

@ -9,15 +9,15 @@
import Foundation import Foundation
public enum ActionCodingKey: String, CodingKey { public enum ActionCodingKey: String, CodingKey {
case type case actionType
} }
public protocol ActionProtocol: Model { public protocol ActionProtocol: Model {
var type: String? { get } var actionType: String? { get }
} }
extension ActionProtocol { extension ActionProtocol {
public var type: String? { public var actionType: String? {
get { return Self.identifier } get { return Self.identifier }
} }
} }

View File

@ -50,7 +50,9 @@ extension KeyedDecodingContainer where Key: CodingKey {
/// Decodes to a registered model based on the identifier, optional. /// Decodes to a registered model based on the identifier, optional.
public func decodeModelIfPresent<M, TypeKey: CodingKey>(codingKey: KeyedDecodingContainer<K>.Key, typeCodingKey: TypeKey) throws -> M? { public func decodeModelIfPresent<M, TypeKey: CodingKey>(codingKey: KeyedDecodingContainer<K>.Key, typeCodingKey: TypeKey) throws -> M? {
//get the identifier string //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 return nil
} }
@ -72,7 +74,8 @@ extension KeyedDecodingContainer where Key: CodingKey {
/// Decodes an array of registered model based on the identifiers, optional. /// Decodes an array of registered model based on the identifiers, optional.
public func decodeModelsIfPresent<TypeKey: CodingKey>(codingKey: KeyedDecodingContainer<K>.Key, typeCodingKey: TypeKey) throws -> [Model]? { public func decodeModelsIfPresent<TypeKey: CodingKey>(codingKey: KeyedDecodingContainer<K>.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 nil
} }
return try container.decodeModelsIfPresent(typeCodingKey: typeCodingKey) 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. /// 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]]? { public func decodeModels2DIfPresent<TypeKey: CodingKey>(codingKey: KeyedDecodingContainer<K>.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 nil
} }
return try container.decodeModels2DIfPresent(typeCodingKey: typeCodingKey) return try container.decodeModels2DIfPresent(typeCodingKey: typeCodingKey)