1

I have code like

@IBOutlet weak var emailField: UITextField!
@IBOutlet weak var countryField: UITextField!
@IBOutlet weak var cityField: UITextField!

How can i put all this items to array so i can access each of them in a loop?

moonvader
  • 19,761
  • 18
  • 67
  • 116

1 Answers1

2
@IBOutlet weak var emailField: UITextField!
@IBOutlet weak var countryField: UITextField!
@IBOutlet weak var cityField: UITextField!

...

let array = [emailField, countryField, cityField]

Have a look at the documentation on collection types

edit: you can split the declaration/init of that array

// outside any method
var array = [UITextField]?

// in viewDidLoad
self.array = [emailField, countryField, cityField]
Diego Freniche
  • 5,225
  • 3
  • 32
  • 45
  • thanks it works if i put this code in ViewDidLoad. in other case i have an error that my class doesn't have member called 'emailField' – moonvader Aug 23 '15 at 10:06