Skip to content

Instantly share code, notes, and snippets.

@yannxou
Created January 21, 2019 13:52
Show Gist options
  • Select an option

  • Save yannxou/853c3818824e19846f5d4fa1e88360de to your computer and use it in GitHub Desktop.

Select an option

Save yannxou/853c3818824e19846f5d4fa1e88360de to your computer and use it in GitHub Desktop.
Float cast to nil (bug?)
import Foundation
import UIKit
func swiftVersion() -> String {
#if swift(>=4.2.1)
return "4.2.1"
#elseif swift(>=4.2)
return "4.2"
#elseif swift(>=4.1)
return "4.1"
#elseif swift(>=4.0)
return "4.0"
#endif
}
let version = "Swift \(swiftVersion())"
let value: Any? = 2.5
let a: Float? = value as? Float
let f: CGFloat? = value as? CGFloat
let b: Double? = value as? Double
let c: Float? = (value as? NSNumber)?.floatValue
@yannxou
Copy link
Copy Markdown
Author

yannxou commented Jan 21, 2019

Result is nil for a and f.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment