0

Please help me to solve a small problem. Im trying to parse string value to int, or I don't know how to say, I'm a newby in programming =) the problem is that Xcode rails on my code:

if let age: Int = ageTextField.text.toInt()
{ }

Xcode tells me to insert ? or ! mark after word "text", but if I make changes he continue to rail on me and tell Value of type string has no member int

Hitesh
  • 896
  • 1
  • 9
  • 22
Sergei
  • 11
  • 1
  • 3
    https://stackoverflow.com/questions/30739460/toint-removed-in-swift-2 – Martin R Sep 27 '17 at 18:29
  • 4
    Please read [Swift Language Guide: The Basics](https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html#//apple_ref/doc/uid/TP40014097-CH5-ID309) especially the section *Optionals* – vadian Sep 27 '17 at 18:39
  • Also see [How is if let evaluated](https://stackoverflow.com/questions/25828301/how-is-swift-if-let-evaluated/38041086#38041086). Also see [what is the meaning of ! or ? in Swift](https://stackoverflow.com/questions/24018327/what-does-an-exclamation-mark-mean-in-the-swift-language/38830543#38830543) – mfaani Sep 27 '17 at 18:51

1 Answers1

1
if let text = textField.text, let int = Int(text) {
   ... 
} else {
   ...
}
John Dough
  • 285
  • 1
  • 7
  • It still doesn't run! :( Xcode refer me to: class AppDelegate: UIResponder, UIApplicationDelegate { and from the right side theres a sign: Thread 1: signal SIGABRT – Sergei Sep 27 '17 at 19:05