Search code examples
swiftswift2

Get integer value from string in swift


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

Solution

  • Swift 2.0 you can initialize Integer using constructor

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