Created
October 19, 2015 12:26
-
-
Save mhuusko5/c34123dcdfeb7d8454af to your computer and use it in GitHub Desktop.
Swift – func deepUnwrap(any: Any) -> Any?
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
func deepUnwrap(any: Any) -> Any? { | |
let mirror = Mirror(reflecting: any) | |
if mirror.displayStyle != .Optional { | |
return any | |
} | |
if let child = mirror.children.first where child.label == "Some" { | |
return deepUnwrap(child.value) | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment