Skip to content

Instantly share code, notes, and snippets.

@westerlund
Created August 17, 2016 13:17
Show Gist options
  • Save westerlund/e7b2975445ca2fba57f023a2500c2c5a to your computer and use it in GitHub Desktop.
Save westerlund/e7b2975445ca2fba57f023a2500c2c5a to your computer and use it in GitHub Desktop.
Unwrap .Optional in an Any
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