This commit is contained in:
Pfeil, Scott Robert 2020-03-02 15:21:01 -05:00
parent 7451c2a5c0
commit d243b9623c

View File

@ -45,25 +45,14 @@ public struct ModelRegistry {
private static func getCategory<T>(for type: T.Type) -> Category? { private static func getCategory<T>(for type: T.Type) -> Category? {
// Temporary code till we find a better solution. // Temporary code till we find a better solution.
//create a string representation of the Type //if this is a protocol composotion, loop through each protocol for a category lookup
let description = String(describing: T.self) let protocols = String(describing: T.self).components(separatedBy: "&").compactMap{$0.trimmingCharacters(in: .whitespaces)}
//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 return protocols.compactMap({ (p) -> Category? in
guard let c = categories[p] else { guard let c = categories[p] else {
return nil return nil
} }
return c return c
}).first }).first
}//otherwise use the description of the type for the lookup
else {
return categories[description]
}
} }
public static func getType<T>(for name: String, with type: T.Type) -> ModelProtocol.Type? { public static func getType<T>(for name: String, with type: T.Type) -> ModelProtocol.Type? {