July 14, 2020

Get a Number From a String in Swift

This is a quick way to get a number (Double in this case) from a String in Swift. Use NSNumberFormatter() from the Foundation Framework to do it. It also handles the reverse scenario of getting a string from number.

numberFromString
NSNumberFormatter().numberFromString(stringValue as String)!.doubleValue