Get integer value from string in swift
In Swift 3.0
Type 1: Convert NSString to String
let stringNumb:NSString = "1357" let someNumb = Int(stringNumb as String) // 1357 as integer
Type 2: If the String has Integer only
let stringNumb = "1357" let someNumb = Int(stringNumb) // 1357 as integer
Type 3: If the String has Float value
let stringNumb = "13.57" if let stringToFloat = Float(stringNumb){ let someNumb = Int(stringToFloat)// 13 as Integer }else{ //do something if the stringNumb not have digit only. (i.e.,) let stringNumb = "13er4" }