Moving stuff about, renaming

This commit is contained in:
Adam Fowler
2021-03-12 09:55:12 +00:00
parent 02af0ec296
commit 633f494e18
5 changed files with 59 additions and 55 deletions

View File

@@ -0,0 +1,17 @@
func unwrapOptional(_ object: Any) -> Any? {
let mirror = Mirror(reflecting: object)
guard mirror.displayStyle == .optional else { return object }
guard let first = mirror.children.first else { return nil }
return first.value
}
extension Mirror {
func getValue(forKey key: String) -> Any? {
guard let matched = children.filter({ $0.label == key }).first else {
return nil
}
return unwrapOptional(matched.value)
}
}