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? {
|
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)}
|
||||||
|
return protocols.compactMap({ (p) -> Category? in
|
||||||
//split the protocol composition (if there is one)
|
guard let c = categories[p] else {
|
||||||
let protocols = description.components(separatedBy: "&").compactMap{$0.trimmingCharacters(in: .whitespaces)}
|
return nil
|
||||||
|
}
|
||||||
//if this is a protocol composotion, loop through each protocol
|
return c
|
||||||
//for a category lookup
|
}).first
|
||||||
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]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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? {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user