Created
August 17, 2016 13:17
-
-
Save westerlund/e7b2975445ca2fba57f023a2500c2c5a to your computer and use it in GitHub Desktop.
Unwrap .Optional in an Any
This file contains hidden or 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 Mirror { | |
private func unwrap(any: Any) -> Any? { | |
let mirror = Mirror(reflecting: any) | |
if mirror.displayStyle != .Optional { | |
return any | |
} | |
guard let first = mirror.children.first else { | |
return nil | |
} | |
return first.value | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment