These are my Outlets, how can I out all off these in an array?
@IBOutlet weak var progressBar1: UIProgressView!
@IBOutlet weak var progressBar2: UIProgressView!
@IBOutlet weak var progressBar3: UIProgressView!
@IBOutlet weak var progressBar4: UIProgressView!
4
Answers
If you have other types of views you can use
Open the Assistant Editor, right-click and drag from one of your UIProgressView’s or just drag from its "Referencing Outlet Collections" to the code file.
Insert outlet collection
Then you can drag from your swift file’s @IBOutlet to the rest of your UIProgressView’s. Add view to collection
On top declare a variable first like this
and now on ViewDidLoad method you can use this to put all outlets on that array
like this:
Hope you understand.
As mentioned here Swift – IBOutletCollection equivalent you can use IBOutletCollection to do that. You can drag all your views to one IBOutlet array.
For example, you can access the first progressBar like
But you have to careful about the order of progressBars, when you define IBOutletCollections the collection will not be order guaranteed. You can define the for each view and sort by their tags in runtime as mentioned here also Is IBOutletCollection guaranteed to be of correct order?
To order all views by their tags like