I currently have a collection of UITextFields wired from IB to my Swift code. The user has option to tap a button to proceed to the next view, but my app requires all fields to be filled. Below is my method that checks if a text field is empty:
func findEmptyField() -> UITextField? {
for field in fieldsCollection {
if field.text.isEmpty {
return field
}
}
//Return here a value signifying that no fields are empty.
}
This method is only partially implemented, as I'm not sure how & what to return if none of them are empty. The caller of this function checks the return value and performs an action dependent on whether it returns a field or not. I vaguely understand that the optionals feature of Swift can help with this, but I'm not certain how.
What should I make the fn return so that the caller recognizes that none of the fields from the collection are empty?