你能帮帮我吗?我需要了解如何将String转换为Int,Float或Double!当我试图从UITextField获取值并需要这种类型的转换时,会发生此问题!
我过去常常这样做:
var myValue : Float = myTextField.text.bridgeToObjectiveC().floatValue
Run Code Online (Sandbox Code Playgroud)
但是从Xcode 6 beta 6开始它似乎不再起作用了!
我也试过这样:
var str = "3.14"
// Conversion from StringValue to an Int
var intValue : Int = str.toInt()!
// Other converstion from StringValue to an Int
var intOtherValue : Int = Int(str)
// Converstion from StringValue to a Float
var floatValue : Float = str.bridgeToObjectiveC().floatValue
// Converstion from StringValue to a Double
var doubleValue : Double = Double(str)
Run Code Online (Sandbox Code Playgroud)
请帮帮我或告诉我在哪里可以找到答案!非常感谢!