SwiftでDoubleからStringへ変換するサンプル

例1
var numString = “1.0"
var numDouble:Double
numDouble = String.bridgeToObjectiveC(numString)().doubleValue
//numDouble 値:1.0

例2
var numString = “abc"
var numDouble:Double

numDouble = String.bridgeToObjectiveC(numString)().doubleValue
//numDouble 値:0.0

例3
var numString1 = “1.5abc"
var numString2 = “2.abc0"
var numString3 = “abc3.0"
var numDouble:Double

numDouble = String.bridgeToObjectiveC(numString1)().doubleValue
//numDouble1 値:1.5
numDouble = String.bridgeToObjectiveC(numString2)().doubleValue
//numDouble2 値:2.0
numDouble = String.bridgeToObjectiveC(numString3)().doubleValue
//numDouble3 値:0.0

IOS

Posted by arkgame