Hi, I have an ObservableObject class called Category with a Published property called modList of a custom type called ModListDelegate that conforms to the Hashable protocol.
I'm trying to allow users to change which of their predefined mod lists is assigned to a given category, using a picker. The issue is that when I select an item, I don't get a tick next to the selected value, or any indication that the value is being changed. I'm fairly sure the value isn't actually changing.
Here is some relevant code:
class Category: Codable, Identifiable, ObservableObject, Equatable {
@Published var name: String
@Published var items: [Item]
@Published var modList: ModListDelegate?
@Published var printer: PrinterConfiguration?
enum CodingKeys: CodingKey {
case name, items, modList, printer, id
}
var id: UUID
... // initialisers and encoders to conform to Codable
}
struct ModListDelegate: Hashable, Codable, Identifiable {
var name: String
var id: UUID
// note that the Category that initialises this struct is not the one to which it's assigned as a modList
init(_ modList: Category){
name = modList.name
id = modList.id
}
}
struct EditCategoryDefaultsView: View {
@ObservedObject var category: Category
@ObservedObject var menu: Menu
var body: some View {
Section(header: Text("Defaults"), content: {
Picker("Associated printer", selection: $category.printer, content: {
ForEach(menu.printers){ printer in
Text(printer.name).tag(printer)
}
})
Picker("Mod list", selection: $category.modList, content: {
ForEach(menu.modLists){ category in
let modList = ModListDelegate(category)
Text(modList.name).tag(modList) // I have also tried this without .tag()
}
})
})
}
}
Any help appreciated, thanks heaps.