1. first step is to select and create a view controller using cmd + shift + L
  2. now click on view controller ⇒ editor (from top toolbar) ⇒ Embed in ⇒ navigation controller
  3. click on navigation view controller and from the inspectors ⇒ attributes inspector ⇒ tick the is initial view controller option.
  4. click on navigation controller bar and from the left menu select navigation bar then select Prefers Large Titles from the attributes inspector
  5. create two swift file using coca touch class, name one colorstablevc and the other colorsdetailsvc.
  6. select title section which is blank of the view controller and name it to ⇒ Colors from attributes inspector.
  7. add another view controller.
  8. select the top right mini icon of both view controller and set the one adjacent to navigation bar class to colorstablevc and the view color adjacent to that to colorsdetailsvc.
  9. add table view to the view controller adjacent to navigation controller and set all constraints to zero from add new constraints(located bottom right third icon) and untick constraints to margins add all constraints and then select save area and set it zero (its the bottom constraint).
  10. click table view and add a prototype cell from attributes inspector.
  11. Select prototype cell and name it ColorCell in indentifier from attributes inspector.
  12. click on the top right of view controller adjacent to navigation bar and hold control and drag it to the other view controller and set it to show.
  13. now from the left side of view controller go to view ⇒ hold control and select table view icon and drag it to the top upper right icon of the view controller adjacent to the navigation view controller and then first select delegate and then do the same and select dataSource.
  14. add this code after everything in the colorstablevc swift file (functionality is written in comments)
extension ColorsTableVC: UITableViewDelegate, UITableViewDataSource {
    //how many rows to show
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 50
    }
    //what to show
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        return UITableViewCell()
    }
    // moves screen to next view controller
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        performSegue(withIdentifier: "ToColorsDetailVC", sender: nil)
    }
}

  1. then clear all and write this. what’s happening here is that we are creating a function to create random number than creating a function to store that in an array 50 times and then showing it by adding the function in the override function block.
import UIKit

class ColorsTableVC: UIViewController {

    // an array to store all colors
    var colors:[UIColor] = []
    
    override func viewDidLoad() {
        super.viewDidLoad()
        addRandomColors()

        // Do any additional setup after loading the view.
    }
    
    func addRandomColors() {
        for _ in 0..<50 {
            colors.append(createRandomColor())
        }
    }
    
    // function that creates a random color
    func createRandomColor() -> UIColor {
        let randomColor = UIColor(red:  CGFloat.random(in: 0...1),
                                  green: CGFloat.random(in: 0...1),
                                  blue: CGFloat.random(in: 0...1),
                                  alpha: 1)
        return randomColor
    }
    
    // this function sets background color in ColourCetailsVC swift file
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        let destVC = segue.destination as! ColorsDetailsVC
        destVC.color = sender as? UIColor
    }
}

extension ColorsTableVC: UITableViewDelegate, UITableViewDataSource {
    // viewing cells equal to the number of length of array i.e if array is of 50
    // length so it'll view 50 cells.
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return colors.count
    }
    
    // sets color of cells to the color corresponding to number of index in the colors array
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        guard let cell = tableView.dequeueReusableCell(withIdentifier: "ColorCell") else {
            return UITableViewCell()
        }
        let color = colors[indexPath.row]
        cell.backgroundColor = color
        return cell
    }
    // moves screen to next view controller
    // this will also trigger prepare for segue override funciton
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let color = colors[indexPath.row]
        performSegue(withIdentifier: "ToColorsDetailVC", sender: color)
    }
}
  1. And write this in colorsdetailsvc swift file after clearing it entirely
import UIKit

class ColorsDetailsVC: UIViewController {
    
    // takes data from ColoursTableVC
    var color: UIColor?

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // if color contains value set that as background color  else set blue as background color
        view.backgroundColor = color ?? .blue

        // Do any additional setup after loading the view.
    }
    
}