I'm trying to make a mixed picker in swift ui. Means: first part is made of values from a constant, second part is made of core data entity values.
My Code so far
- Structs
struct StandardArten: Identifiable, Hashable {
var id: UUID = UUID()
var name: String
}
struct Constants {
static let standardKontakte = [
StandardArten(name: "Hausarzt")
]
}
- picker
Picker("Kategorie", selection: $kategorie) {
Text("Bitte wählen...").tag(Optional<UUID>(nil))
ForEach(Constants.standardKontakte, id: \.id) { kat in
Text(kat.name).tag(kat.id)
}
Divider()
ForEach(adressKategorien, id:\.id) { kat in
Text(kat.name ?? "ohne Titel").tag(kat.id)
}
}
The picker is displayed properly (see image), but selecting "Hausarzt" the picker "jumps back" to the old value.
So what am I doing wrong here?
Additional information:
$kategorie
is declared as @State var kategorie: UUID?