If the variable comes from an array then the label is not automatically refreshed. Is there a specific reason for that?
@State private var categories: [ItemCategory] = getCategories()
@State private var isOn = true
Button(action: {
categories[1].chose = !categories[1].chose
}, label: {
Text(categories[1].chose ? "Add" : "Remove") // not automatically refreshed, only with view change (go to an other and then back)
})
Button(action: {
isOn = !isOn
}, label: {
Text(isOn ? "Add" : "Remove") // automatically refreshed
})
Update:
Sorry I missed the ItemCategory
class ItemCategory: Codable, Equatable, Identifiable, Hashable {
var name: String
var items: [Item]
var chose: Bool
var collapsed: Bool
}
ItemCategorya class? Please add the code for it.