@Model class Planner {
//var id: UUID = UUID()
var grade: Double = 4.0
var kumi: Double = 4.0
var period: Double = 1.0
var dates: Set<DateComponents> = []
init(
grade: Double = 4.0, kumi: Double = 4.0, period: Double = 1.0, dates: Set<DateComponents> = []
)
{
self.grade = grade
self.kumi = kumi
self.period = period
self.dates = dates
}
}
snippet of code from PlannerView.swift
var body: some View {
NavigationStack {
Group {
if planner.isEmpty {
ContentUnavailableView("Setup Classes.", systemImage: "book.fill")
} else {
List {
ForEach(planner) { planner in
NavigationLink {
PlannerEditView(planner: planner)
} label: {
HStack(spacing: 10) {
VStack(alignment: .leading) {
if planner.dates.count == 0 {
ContentUnavailableView("No class dates.", systemImage: "book.fill")
} else {
//let jsonData = planner.dates(using: .utf8)!
//if let decodedPlanner = try? JSONDecoder().decode([Planner], from: planner.dates) {
// dates = decodedPlanner
// }
Text("Dates: \(planner.dates))")
}
}
}
}
}
.onDelete { indexSet in
indexSet.forEach { index in
let plan = planner[index]
context.delete(plan)
}
}
}//list
.listStyle(.plain)
}//if stmt
}//group
}//Navigation Stack
So I'm at a loss how to display the dates on the ListView.swift file in a Text box such as March 14, 2025 and March 16, 2025.
I can see the JSON data but I don't know the syntax of decoding the JSON data. Plus, I'm not using a JSON file, only a multidatepicker.
The 2nd issue is using the @Query macro and filtering records. I would like to use the @Query macro and only retrieve all records for the current date (today). Since the Model uses Set and DateComponents, I don't know the correct syntax.