因此,在swift 3中,我只想循環訪問textField outlet集合,如果textField.text =「」,然後做一些事情。我做了以下,但我相信應該有一個更優雅的解決方案,其中我不必使用數組來檢查空的文本字段,但直接從文本字段集合中檢查它。在textField集合中查找空的textField
@IBOutlet var playerNamesCollection: [UITextField]!
//add names to an array
var namesArray = [String]()
for i in 0...8 {
namesArray.append(playerNamesCollection[i].text!)
}
//and then verify that array
for i in 0...8 {
if namesArray.contains("") {
print("missing a name")
} else {
print("all textFieldsFilled")
}