From d243b9623c420395feb7521889fa663ebff226c4 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 2 Mar 2020 15:21:01 -0500 Subject: [PATCH] condense --- .../MVMCore/Models/Model/ModelRegistry.swift | 27 ++++++------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index 54e1d89..b002175 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -45,25 +45,14 @@ public struct ModelRegistry { private static func getCategory(for type: T.Type) -> Category? { // Temporary code till we find a better solution. - //create a string representation of the Type - let description = String(describing: T.self) - - //split the protocol composition (if there is one) - let protocols = description.components(separatedBy: "&").compactMap{$0.trimmingCharacters(in: .whitespaces)} - - //if this is a protocol composotion, loop through each protocol - //for a category lookup - if protocols.count > 1 { - return protocols.compactMap({ (p) -> Category? in - guard let c = categories[p] else { - return nil - } - return c - }).first - }//otherwise use the description of the type for the lookup - else { - return categories[description] - } + //if this is a protocol composotion, loop through each protocol for a category lookup + let protocols = String(describing: T.self).components(separatedBy: "&").compactMap{$0.trimmingCharacters(in: .whitespaces)} + return protocols.compactMap({ (p) -> Category? in + guard let c = categories[p] else { + return nil + } + return c + }).first } public static func getType(for name: String, with type: T.Type) -> ModelProtocol.Type? {