I’m trying to select the entity from CoreData storage, but the Picker is not functional — it does not show the selected entity.
My code:
import SwiftUI
struct SampleView: View {
@FetchRequest(entity: Aircraft.entity(), sortDescriptors: [NSSortDescriptor(keyPath: \Aircraft.model, ascending: true)]) var aircrafts: FetchedResults<Aircraft>
@State private var selection: UUID? = UUID()
var body: some View {
NavigationView {
VStack {
Form {
Picker(selection: $selection, label: Text("Picker")) {
ForEach(aircrafts, id: \.self) { aircraft in
Text(aircraft.model ?? "Unknown")
}
}
}
}
}
}
}