I have a table view that every time I create a new row, a different color is randomly created to change it`s background. using this function:
func getRandomColor() -> UIColor{
let red:CGFloat = CGFloat(drand48())
let green:CGFloat = CGFloat(drand48())
let blue:CGFloat = CGFloat(drand48())
return UIColor(red:red, green: green, blue: blue, alpha: 1.0)
}
I store the color in an array, doing this I want to avoid equals colors in my table view. The array is populated when the table view is created in table view cellForRow, like this:
colors.append(category.color as! UIColor)
category is my object.
The problem is when I close the app and starts it again. The memory continuos and start to randomly create the same colors. So I'm trying to compare colors to keep generating colors until it is a new color. Using this function:
func validateColor(color: UIColor) -> Bool {
let primeiraCor = colors.first! as UIColor
if primeiraCor == color {
return false
} else {
return true
}
}
colors is my array of color, and color the color I want to compare. But every time the function is called it's return true.
What can I do?