joda joda - 1 year ago 79
Swift Question

access to elements in IBOutletCollection

I have an

IBOutletCollection
of
UIImageView


now I need to access to imges in it, how I can do it?

I just can access to the first and the list by this code

myCollection.first?.image
myCollection.last?.image


I need to access to other images

Answer Source

IBOutletCollection is an Array, hence to access its element we can use subscripts, like we do to access elements from normal array.

So to access its elements:

myCollection[0].image //or myCollection.first?.image 
myCollection[1].image 
myCollection[2].image
....
myCollection.last?.image