How to lay through Outlets from a UIViewController with Swift

I am wondering if you can skip all exits UIViewControllerat a speed.

Specifically, I want to check if each text field is populated by the user.

+4
source share
2 answers

This is what the Outlet collection is for. Drag all your text fields into the same Outlet Collection in InterfaceBuilder and create @IBOutletfor this collection in your class file:

To create a collection of output data in InterfaceBuilder, ctrl-drag from the first UITextFieldto your class file in the editor assistant. Then select the Outlet Collection:

enter image description here

ctrl- UITextField @IBOutlet, :

enter image description here

.

@IBOutlet var textFields: [UITextField]!

func checkTextFields() {
    for textField in self.textFields {
        ... // do your checks
    }
}
+12

, , , .

for view in self.view.subviews as [UIView] {
    if let textField = view as? UITextField {
        if textField.text == "" {
            // textfield is empty
            return
        }
    }
}
+1

All Articles