A float is not the same as a CGFloat. You must pass CGFloat to UIColor. Note. You must name your structures starting with a capital letter.
struct Color { let r: CGFloat let g: CGFloat let b: CGFloat } class ViewController: UIViewController{ func setPixels(image: [Color], pixel: Int) { let alpha: CGFloat = 1 let pixelView = view.viewWithTag(pixel) as! UIImageView pixelView.backgroundColor = UIColor( red: image[pixel].r, green: image[pixel].g, blue: image[pixel].b, alpha: alpha ) } }
source share