Files
T. R. Bernstein 6061715025
Some checks failed
CI / macOS (push) Has been cancelled
CI / linux (swift:6.0) (push) Has been cancelled
CI / linux (swift:6.1) (push) Has been cancelled
CI / linux (swift:6.2) (push) Has been cancelled
CI / windows (6.1) (push) Has been cancelled
Adapt project for Astzweig
2025-09-29 15:03:48 +02:00

18 lines
600 B
Swift

extension Mirror {
/// Return value from Mirror given name
func getValue(forKey key: String) -> Any? {
guard let matched = children.filter({ $0.label == key }).first else {
return nil
}
return unwrapOptional(matched.value)
}
}
/// Return object and if it is an Optional return object Optional holds
private 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
}