For one line I choose the color, everything works. If I create the second line and set a different color, the first one changes its color and both of the same color. How to make the colors different? enter image description here

Color pickup function

@IBAction func backgroundColor(_ sender: AnyObject) { if let well = sender as? NSColorWell { let color = well.color MQTTSubscribeVC.preferenceTableColor = color TableBgColorChangedNotification), object: self) } } 

Display

 func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? { cell.messageLabel.backgroundColor = color.preferenceTableColor 

    1 answer 1

    Set the tag for each line, and then for each line with the desired tag to set the desired color.

     cell.tag = 1 if cell.tag == 1 { cell.backgroundColor = color } 

    More Swifty is through switch:

     switch cell.tag { case 1: cell.backgroundColor = color1 case 2: cell.backgroundColor = color2 default: break } 
    • Lines can be as many as you want each not numbered - user233428
    • cell.tag = indexPath.row - Vitali Eller