In a Swift app, I am attempting to nest structures for greater clarity. Here is the code:
struct ColorStruct {
var colorname: String = ""
struct RGB {
var red: Int = 0
var green: Int = 0
var blue: Int = 0
}
}
I can access a ColorStruct
element (example: "colorname") as long as it isn't nested.
Q: What am I failing to understanding about how to properly access the "red" variable?
var newColor = ColorStruct()
newColor.colorname = "Red"
newColor.RGB.red = 255 // Results in error:
// Static member 'RGB' cannot be used on instance of type `ColorStruct`