If we go back to your previous question regarding the array of ImageViews then we can build on that.
Assuming that:
let square1 = UIIMageView()
let square2 = UIImageView()
...
...
...
let square9 = UIImageView()
Let’s also assume that your array is defined like this:
var viewArray: [UIImageView]
Put all the squares in the ViewArray.
viewArray = [square1,square2,square3,square4,square5,square6,square7,square8,square9]
If you had assigned a backgroundColor differently to each of the squares like:
square1.backgroundColor = .red
square2.backgroundColor = .green
square3.backgroundColor = .blue
square4.backgroundColor = .purple
square5.backgroundColor = .orange
square6.backgroundColor = .gray
square7.backgroundColor = .magenta
square8.backgroundColor = .cyan
square9.backgroundColor = .brown
then you can test each square by referencing the square in the relevant array position
let square = viewArray[0]
// the first element in the array
then you can test image background colour like this:
if square.backgroundColor == .white {
// do something
} else if square.backgroundColor == .red {
// do something different
} else if ....
....
....
}
a better way to do the test is using switch
switch square.backgroundColor {
case UIColor.red:
// do something
case UIColor.green:
// do something else
case UIColor.blue:
// do something else
...
...
...
}
Does the make sense?