My ViewController
/ MARK: Properties
@IBOutlet weak var textInput: UITextField!
@IBOutlet weak var labelTop: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
textInput.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: UITextFieldDelegate
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
func textFieldDidEndEditing(textField: UITextField) {
if (textInput != nil){
labelTop.text = "Searching for \(textField.text)"
textInput.enabled = false
}
}
When I press return on the textfield the code
labelTop.text = "Searching for \(textField.text)"
is called. However the text of labelTop looks like:
Searching for Optional("the text")
I looked at optionals (most times they use ? instead of ! right?) but do not understand how I should get the value without the surrounding 'Optional("")'