Skip to content

Instantly share code, notes, and snippets.

@giovani-pereira-ifood
Last active January 10, 2020 20:56
Show Gist options
  • Save giovani-pereira-ifood/d360650a2e4492ac9453f4a6184f2ae3 to your computer and use it in GitHub Desktop.
Save giovani-pereira-ifood/d360650a2e4492ac9453f4a6184f2ae3 to your computer and use it in GitHub Desktop.
Mirror extract extension
extension XCTestCase {
enum MirrorConstants: String {
case interactor
case presenter
case router
}
func mirror<T>(property: MirrorConstants, ofType: T.Type, from object: Any?) -> T? {
guard let object = object else { return nil }
let mirror = Mirror(reflecting: object)
return mirror.children.first {
$0.label == property.rawValue
}?.value as? T
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment