diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index ee741bf..e73437c 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -49,13 +49,7 @@ extension KeyedDecodingContainer where Key: CodingKey { /// Decodes to a registered model based on the identifier, optional. public func decodeModelIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> T? { //get the identifier string - var container: KeyedDecodingContainer? - do { - container = try nestedContainer(keyedBy: C.self, forKey: codingKey) - } catch { - return nil - } - guard let identifier = try container?.decodeIfPresent(String.self, forKey: typeCodingKey) else { + guard let container = try? nestedContainer(keyedBy: C.self, forKey: codingKey), let identifier = try? container.decodeIfPresent(String.self, forKey: typeCodingKey) else { return nil } @@ -77,8 +71,10 @@ extension KeyedDecodingContainer where Key: CodingKey { /// Decodes an array of registered model based on the identifiers, optional. public func decodeModelsIfPresent(codingKey: KeyedDecodingContainer.Key, typeCodingKey: C) throws -> [Model]? { + guard var container = try? nestedUnkeyedContainer(forKey: codingKey) else { + return nil + } var models = [Model]() - var container = try nestedUnkeyedContainer(forKey: codingKey) var containerCopy = container while !container.isAtEnd { let nestedContainer = try container.nestedContainer(keyedBy: C.self)