Last active
January 10, 2020 20:56
-
-
Save giovani-pereira-ifood/d360650a2e4492ac9453f4a6184f2ae3 to your computer and use it in GitHub Desktop.
Mirror extract extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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