Created
January 29, 2015 02:48
-
-
Save indragiek/6b500e84927f0be9c2ae to your computer and use it in GitHub Desktop.
Swift bug when formatting CGFloats
This file contains hidden or 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
import Cocoa | |
// Doesn't work for CGFloats | |
let a: CGFloat = 1.0 | |
let b: CGFloat = 2.0 | |
String(format: "%f %f", a, b) // "0.000000 0.000000" | |
// Works for Floats | |
let c: Float = 1.0 | |
let d: Float = 2.0 | |
String(format: "%f %f", c, d) // "1.000000 2.000000" | |
// Works for Doubles | |
let e: Double = 1.0 | |
let f: Double = 2.0 | |
String(format: "%f %f", e, f) // "1.000000 2.000000" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Swift's
String
is extended inFoundation
to include most ofNSString
's initializers—you can see all of them by command-clicking on animport Foundation
statement or on the SwiftDoc.org String page marked with [Foundation].