How to convert a String (numeric) in a Int array in Swift

后端 未结 8 1455
鱼传尺愫
鱼传尺愫 2021-02-13 20:41

I\'d like to know how can I convert a String in an Int array in Swift. In Java I\'ve always done it like this:

String myString = \"123456789\";
int[] myArray = n         


        
8条回答
  •  庸人自扰
    2021-02-13 21:05

    Swift 3 update:

    @appzYourLife : That's correct toInt() method is no longer available for String in Swift 3. As an alternative what you can do is :

    intArray.append(Int(String(chr)) ?? 0)
    

    Enclosing it within Int() converts it to Int.

提交回复
热议问题