Common Swift collection casting or type conversion

Collection of Common Swift Casting  or Type Conversion

String to Double
var a  = "1.5"
var b  = (a as NSString).doubleValue

Double to String
var a : Double = 1.5
var b  = String(format:"%f", a)

Double to Int
var a : Double = 1.5
var b  = Double(a)

String to Float
var a  = "1.5"
var b  = (a as NSString).floatValue

String to Float
var a  = "1.5"
var b  = (a as NSString).intValue


Common Swift collection casting or type conversion Common Swift collection casting or type conversion Reviewed by Edmond Legaspi on Wednesday, January 28, 2015 Rating: 5

No comments:

Powered by Blogger.