Pages

05 July, 2024

Preview canvas crashing because environmentObject not set properly

I have my preview canvas crashing because the environmentObject is not properly set.
The app itself builds and run properly.


Error message.


app crashed due to missing environment of type: TaskModel. To resolve this add .environmentObject(TaskModel(...)) to the appropriate preview.


My View with the #Preview macro looks like this.
struct CopyTaskListScreen: View {
@EnvironmentObject private var taskModel: TaskModel

var body: some View {
NavigationStack {
List(taskModel.tasks.sorted(by:

No comments:

Post a Comment

Thanks