-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
  • 115
  • 2
  • 11

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
  • 8,570
  • 6
  • 46
  • 65
0

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

Dharma
  • 3,007
  • 3
  • 23
  • 38