struct AppointmentView: View
{
@Environment(\.managedObjectContext) var managedObjectContext
@FetchRequest(entity: Appoint.entity(), sortDescriptors: [NSSortDescriptor(keyPath: \Appoint.title , ascending: true)])
var appointments_title: FetchedResults<Appoint>
@State var showAddDate = false
@State var sectionState: [Int: Bool] = [:]
var body: some View
{
NavigationView
{
List
{
ForEach(appointments_title)
{
order in
HStack
{
Text("\(order.title)").font(.headline)
Spacer()
Text("\(order.date, formatter: ContentView.self.taskDateFormat)").font(.headline)
}.contentShape(Rectangle())
.onTapGesture
{
self.sectionState[order] = !self.isExpanded(order)
}
if self.isExpanded(order)
{
Text("\(order.description)”)
}
}
}
.navigationBarTitle("My Appointment")
.navigationBarItems(trailing: Button(action: {self.showAddDate = true}, label: {Image(systemName: "plus.circle").resizable().frame(width: 32, height: 32, alignment: .center)}))
.sheet(isPresented: $showAddDate) {AddDate().environment(\.managedObjectContext, self.managedObjectContext)}
}
}
func isExpanded(_ order:Int) -> Bool
{
sectionState[order] ?? false
}
}
When I try to run this code, I will get this error message;
Cannot convert value of type 'FetchedResults < Appoint >' to expected
argument type 'Range < Int >'
Is there a way to convert 'FetchedResults < Appoint > ' into 'Range < Int >' ?