In the Chart section of the SwiftUI manual, we see a data array made from literals as so:
var stackedBarData: [ToyShape] = [
.init(color: "Green", type: "Cube", count: 2),
.init(color: "Green", type: "Sphere", count: 0),
.init(color: "Green", type: "Pyramid", count: 1),
.init(color: "Purple", type: "Cube", count: 1),
.init(color: "Purple", type: "Sphere", count: 1),
.init(color: "Purple", type: "Pyramid", count: 1),
.init(color: "Pink", type: "Cube", count: 1),
.init(color: "Pink", type: "Sphere", count: 2),
.init(color: "Pink", type: "Pyramid", count: 0),
.init(color: "Yellow", type: "Cube", count: 1),
.init(color: "Yellow", type: "Sphere", count: 1),
.init(color: "Yellow", type: "Pyramid", count: 2)
]
That's a whole of of repetition. Now, when I make structs I often make an initializer which leaves out the labels, so we could get to here:
var stackedBarData: [ToyShape] = [
// ToyShape(color: String, type: String, count: Int)
.init("Green", "Cube", 2),
.init("Green", "Sphere", 0),
.init("Green", "Pyramid", 1),
...
]
My idea is that in the narrow context of an array literal, it'd be nice if we could go all the way to:
var stackedBarData: [ToyShape] = [
// ToyShape(color: String, type: String, count: Int)
("Green", "Cube", 2)
("Green", "Sphere", 0)
("Green", "Pyramid", 1)
...
]
Has anyone played with that idea? I wouldn't be surprised, but I don't recall seeing it. I feel like it fits the Swift idiom of being able to optionally leave out assumable things.