Skip to content

Instantly share code, notes, and snippets.

@stevedoyle
Created January 22, 2015 09:53
Show Gist options
  • Save stevedoyle/4a3b46a040a7b5c05239 to your computer and use it in GitHub Desktop.
Save stevedoyle/4a3b46a040a7b5c05239 to your computer and use it in GitHub Desktop.
Working with NSNumber in Swift
var targetDistance: NSNumber = 4000
var completedDistance: NSNumber = 121.7
var percentComplete: Float
// NSNumber can contain different types, so need to be explicit about the type of its value
// when using it in arithmetic
percentComplete = (completedDistance.floatValue / targetDistance.floatValue) * 100
println(percentComplete)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment