From 441fb0c0e15683cdbc387773a1db362a00c47d93 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 12 Feb 2020 21:35:55 -0500 Subject: [PATCH] Small fix and clean --- .../Models/ActionType/ActionModelProtocol.swift | 3 --- MVMCore/MVMCore/Models/Model/ModelRegistry.swift | 14 +++----------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/MVMCore/MVMCore/Models/ActionType/ActionModelProtocol.swift b/MVMCore/MVMCore/Models/ActionType/ActionModelProtocol.swift index 00997fb..e6dfd27 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionModelProtocol.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionModelProtocol.swift @@ -17,9 +17,6 @@ public protocol ActionModelProtocol: Model { var actionType: String? { get set } var extraParameters: JSONValueDictionary? { get set } var analyticsData: JSONValueDictionary? { get set } - - static var categoryName: String { get } - static var categoryCodingKey: String { get } // Temporary fix till server changes var title: String? { get set } diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index 7bf560f..ad2fb16 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -33,13 +33,7 @@ public struct ModelRegistry { /// Registers models for Atomic use. public static func register(_ type: M.Type) throws { - var category: Category - - if let c = categories[M.categoryName] { - category = c - } else { - category = Category(name: M.categoryName, codingKey: M.categoryCodingKey) - } + var category = categories[M.categoryName] ?? Category(name: M.categoryName, codingKey: M.categoryCodingKey) // Check to ensure the Category/Type combination doesn't exist. if category.instanceTypes[M.identifier] != nil { @@ -59,11 +53,9 @@ public struct ModelRegistry { } private static func getCategory(for typeString: String) -> Category? { - for (_, value) in categories where value.codingKey == typeString { return value } - return nil } @@ -71,7 +63,7 @@ public struct ModelRegistry { return getCategory(for: typeString)?.instanceTypes[name] } - public static func getCodingKey(for type: T.Type) throws -> AnyCodingKey{ + public static func getCodingKey(for type: T.Type) throws -> AnyCodingKey { guard let category = getCategory(for: type) else { throw ModelRegistry.Error.decoderOther(message: "decodeModelsIfPresent only works for objects implementing the Model protocol") } @@ -196,7 +188,7 @@ public extension KeyedEncodingContainer where Key: CodingKey { } /// Convenience function for encoding the container into a list of lists of Models. needs instance type as input paramaeter list - mutating func encodeModels2D(_ list: [[Model]]?, forKey key:KeyedEncodingContainer.Key) throws { + mutating func encodeModels2D(_ list: [[Model]]?, forKey key: KeyedEncodingContainer.Key) throws { guard let list = list else { return } var unkeyedContainer = nestedUnkeyedContainer(forKey: key)