Skip to content

Instantly share code, notes, and snippets.

@mhuusko5
Created October 19, 2015 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhuusko5/c34123dcdfeb7d8454af to your computer and use it in GitHub Desktop.
Save mhuusko5/c34123dcdfeb7d8454af to your computer and use it in GitHub Desktop.
Swift – func deepUnwrap(any: Any) -> Any?
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