I have a simple CollectionView grid with 9 cells (generated dynamically), in each cell is a red square and a yellow square.
I have a timer on the page.
I have used the randomElement function to identify one of the generated cells in the array.
I now want to take this randomly selected cell and if it is yellow, change the alpha setting so that it appears to go from one colour to another.
Here is the code and the error
'''
@objc func timerElapsed() {
seconds -= 1
timerLabel.text = "\(seconds)"
if seconds <= 0 {
timer?.invalidate()
}
if seconds > 0 {
let randomcell = cellArray.randomElement()
if randomcell == YellowSquare.GridCell { !Use of unresolved identifier 'YellowSquare'
}
But when I use a print function the output for 'randomcell' is YellowSquare.Gridcell or RedSquare.Gridcell, so how do I present this information correctly. I have tried a variety of parentheses and syntax methods.
Apologies if this is basic or confusing, I only started learning Swift yesterday. And I have read the documentation on randomElement and was none the wiser.
Thank you in advance
Aucun commentaire:
Enregistrer un commentaire