So I am very very new to coding in general and I am taking a class learning about creating apps in xcode. We were assigned to make our first app from scratch. My idea was to make a guessing game where the user is given a picture up close, and they are have to guess what it is. I want it where there's a label, textfield and button. They type their guess in the textfield, click the button to check their answer, and then the label text changes saying "you are wrong" or you are correct". I've looked all over and haven't found much on how to change a label's text depending on what is entered in the textfield. I assumed that I would use an if-else statement but it seems like that is only for integers. Any help on what to do? I've connected everything also. Thanks a lot in advance!
How to have label text change to message after user types in textfield?
You will have IBOutlet for a UILabel and a UITextField in your controller, and the label and textField in the nib connected to them.
@IBOutlet weak var myTextField: UITextField!
@IBOutlet weak var myLabel: UILabel! You load a var (result) at the same time you load the image
A basic way to do this is to test the textField at the end of editing :
@IBAction func textFieldDoneEditing(sender: UITextField) {
if sender.text == result { // you should probably force everything to lowercase, to avoid wrong test
myLabel.text = "Correct"
} else {
myLabel.text = "Incorrect"
}In the connection inspector on the extreme right panel, you connect the "did end on exit" small dot to this IBAction.