I tried to use ForEach()
to generate labels in a list
List {
ForEach(objects) { obj in
Label(obj.id, systemImage: obj.icon)
}
}
The icon of each label is decided by its id so I use lazy var
to define the struct
struct Object: Identifiable {
var id:Int
lazy var icon:String={
// ...
}
}
And create an array for each one
var objects = [
Object(id:1),
Object(id:2),
// ...
]
But it throw an error like Cannot use mutating getter on immutable value: 'obj' is a 'let' constant