parsing to double any data type in swift code example

Example 1: parsing to double any data type in swift

if let cost = Double(textField.text!) {
    print("The item is valued at: \(cost)")
} else {
    print("Not a valid number: \(textField.text!)")
}

Example 2: parsing to double any data type in swift

let wholeNumber = Int("27")
let smallInt = Int16("34")
let largeInt = Int64("39384")

Example 3: parsing to double any data type in swift

let lessPrecisePI = Float("3.14")
let morePrecisePI = Double("3.1415926536")
let width = CGFloat(Double("200.0")!)

Tags:

Misc Example