condense
This commit is contained in:
parent
7451c2a5c0
commit
d243b9623c
@ -45,25 +45,14 @@ public struct ModelRegistry {
|
||||
|
||||
private static func getCategory<T>(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<T>(for name: String, with type: T.Type) -> ModelProtocol.Type? {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user