Creating an array of all objects of a class

Viewed 97

Is there a way of creating an array of all colour objects created? So that every time a new colour is added, it is also automatically added to the array?

class Colours {
    var colourName: String
    var colourShades: [String?]


    init(colourName: String, colourShades: [String?]) {
        self.colourName = colourName
        self.colourShades = colourShades
    }


}

var red = Colours(colourName: "Red", colourShades: ["Crimson", "Cherry", "Rose"])


var blue = Colours(colourName: "blue", colourShades:["Ice", "Baby", "Royal"])

To give some context I am attempting to develop an app for IOS which includes a table of colours. Then when a user clicks on a colour it will take them to another table which has shades of that colour.

I want the array of colours so that I can automatically fill in the rows of the table, and then when a user adds a new colour it will automatically add a new row.

4 Answers
Related