Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Egor Bedunkevich
605 PointsSo I get an error when converting textfiled.toInt()
I want to test something out, however when I try to perform any math in my code I get an error: Binary operator "=="" can not be applied to type string and int.
Here is my code:
@IBOutlet weak var textField: UITextField! @IBOutlet weak var label: UILabel! @IBAction func buttonPressed(sender: AnyObject) {
self.textField.text.toInt()
if textField.text == 10 {
println("Works.")
}
}
}
1 Answer
Jhoan Arango
14,575 PointsTry this :
@IBOutlet weak var textField: UITextField!
@IBOutlet weak var label: UILabel!
@IBAction func buttonPressed(sender: AnyObject) {
let text = textField.text
let textToInt = text!.toInt()
if textToInt == 10 {
println("Works.")
}
}
Let me know if that works for you.