Consider the following code:
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
let validator:NSPredicate = NSPredicate(format:"SELF MATCHES %@","[A-Za-z0-9- ]+")
if(validator.evaluateWithObject(string) || string == "" ) {
self.process(textField)
return true
}
else {
return false
}
}
I want to run self.process (textField) AFTER the return statement, because before it the text in the text field has not changed yet. This made me wonder why I can't just execute some code after the return statement? Why do functions always stop when the return statement is executed?
I understand that traditionally, what does return mean, but is there an alternative? For example, is there a way to return a value from a function and then still continue?
On the one hand, this seems like a stupid question, but on the other hand, I feel that I cannot be the first to ever want to do this. It would be nice if I could remove something to work in the next cycle of the cycle cycle, so maybe there is something in the GCD that could help me.
source
share