In swift a String can be converted into a Int in a very easy and safe way. Below example will show how we can easily convert a String to an Int value
let stringValue = "235" if let intValue = Int(stringValue) { print("\(intValue)") }
nil coalescing can also be used if we wish to return a default value in case of a invalid string
let stringValue = "235" let intValue = Int(stringValue) ?? 1 // default value of 1 incase of a invalid stringValue print("\(intValue)")
Hope this helps!!!