Get integer value from string in swift

后端 未结 12 1823
小蘑菇
小蘑菇 2020-11-27 17:14

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

12条回答
  •  离开以前
    2020-11-27 18:05

    If you are able to use a NSString only.

    It's pretty similar to objective-c. All the data type are there but require the as NSString addition

        var x = "400.0" as NSString 
    
        x.floatValue //string to float
        x.doubleValue // to double
        x.boolValue // to bool
        x.integerValue // to integer
        x.intValue // to int
    

    Also we have an toInt() function added See Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/us/jEUH0.l page 49

    x.toInt()
    

提交回复
热议问题