Skip to content

Instantly share code, notes, and snippets.

@debreuil
Created June 12, 2014 03:22
Show Gist options
  • Save debreuil/b8ec22d8e2a28e1aa1c9 to your computer and use it in GitHub Desktop.
Save debreuil/b8ec22d8e2a28e1aa1c9 to your computer and use it in GitHub Desktop.
// How to you safely convert an AnyObject with a number value into a Double?
let anyDouble:AnyObject = 6.41
if let xx = anyDouble as? NSNumber {
println( Double(xx)) // prints 6.41
}
// will throw an error if the conversion fails!
let casted = Double(anyDouble as NSNumber) // 6.41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment