I am trying to transfer CDListModel to my Today View but I can not do it properly. So that I can see how many reminders I have totally today in list.reminders.count. Right now I am getting 0
struct Today: View {
@Environment(\.managedObjectContext) private var viewContext
@ObservedObject var list: CDListModel
@State var isTodayTapped = false
var body: some View {
Button(action: {
self.isTodayTapped.toggle()
}) {
ZStack{
RoundedRectangle(cornerRadius: 15)
.foregroundColor(.white)
HStack(alignment: .top, spacing: 100) {
Text(String(list.reminders!.count))
}
}
}
.fullScreenCover(isPresented: $isTodayTapped) {
TodayView()
}
}
}
MainPageView
struct MainPageView: View {
@Environment(\.managedObjectContext) private var viewContext
var list: CDListModel
var body: some View {
ZStack {
NavigationView {
ZStack {
VStack{
HStack(spacing: 20){
Today(list: list) //What should I send here?
.environment(\.managedObjectContext, viewContext)
}
}
}
}
}
}
}
ContentView
struct ContentView: View {
@Environment(\.managedObjectContext) private var viewContext
@State var selectedList = ListModel(color: "", text: "", reminders: [])
var body: some View {
MainPageView(selectedList: $selectedList, list: CDListModel())
.environment(\.managedObjectContext, viewContext)
}
}
CDListModel? Your code doesn't show anything about CoreData. You aren't observing, fetching, etc. - lorem ipsum