-2

I'm working in a small project and I faced this problem : text field is String by default so I need to take the input and convert it to integer then calculate I was searching for a way to solve the converting problem and I didn't find any working solution so can any one help me please ?

keloa
  • 105
  • 2
  • 10

2 Answers2

1
try like this 

In Swift 2.0, toInt(),replaced with initializers. (In this case, Int(someString).)

 let myString : String = "50"
    let x : Int? = Int(myString)

    if (x != null) {
       // converted String to Int
    }
Sport
  • 7,880
  • 6
  • 42
  • 62
0

myString.toInt() - convert the string value into int .

Dharma
  • 2,965
  • 3
  • 20
  • 36