I have some trouble with pickers with Fetchrequest. I can display a list but can't manage the picker.
struct DepenseView: View {
@Environment(\.managedObjectContext) var moc
@FetchRequest(sortDescriptors: []) var TypeDepenses: FetchedResults<TypeDepense>
@State var selectedDepense : String = "Autre"
var body: some View {
List {
ForEach(TypeDepenses) { typb in
Text(typb.type ?? "Unknown Title")
}
}
List {
Picker("Type", selection: $selectedDepense){
ForEach(TypeDepenses){ type in
Text(type.type ?? "Unknown Title").tag(type.type)
}
Text("Autre").tag("Autre")
}
}
}
}
I tried to add .tag with different possibilities (.tag(type), .tag(type.type), .tag(type.id), ...). I just want the picker list to be different type from the data base. I can see them but I can't select them.