Get integer value from string in swift

Logan picture Logan · Jun 3, 2014 · Viewed 167.3k times · Source

So I can do this:

var stringNumb: NSString = "1357"

var someNumb: CInt = stringNumb.intValue

But I can't find the way to do it w/ a String. I'd like to do something like:

var stringNumb: String = "1357"

var someNumb: Int = Int(stringNumb)

This doesn't work either:

var someNumbAlt: Int = myString.integerValue

Answer

Buru picture Buru · Jun 12, 2015

Swift 2.0 you can initialize Integer using constructor

var stringNumber = "1234"
var numberFromString = Int(stringNumber)