Getting 17 errors while using SwiftData, Xcode 15 beta 8

I was converting a SwiftUI view to use persistence with SwiftData when I got 17 errors in Xcode! I have no idea what happened when I got those errors, and there were too many to search up, so I decided to ask here. So can anyone help me? Here is the code:

//
//  TodoListView.swift
//  Vision To-Do
//
//  Created by Nicolas Tama on 9/3/23.
//

import SwiftUI
import SwiftData

struct TodoListView: View {
    @Environment(\.modelContext) private var modelContext
    @State var list: TodoList
    
    @State private var showAddTodoAlert: Bool = false
    @State private var newTodoTitle: String = ""
    
    var body: some View {
    List {
        Section("Todo") {
            ForEach(list.items.filter { $0.isDone == false }){ item in
                HStack {
                    Button {
                        item.isDone.toggle()
                            }
                        }
                    } label: {
                        Image(systemName: item.isDone ? "circle.fill" : "circle")
                    }
                    Text(item.title)
                    Spacer()
                }
            }
        }
        
        Section("Done") {
            ForEach(list.items.filter { $0.isDone }){ item in
                HStack {
                    Button {
                        item.isDone.toggle()
                        }
                    } label: {
                        Image(systemName: item.isDone ? "circle.fill" : "circle")
                    }
                    Text(item.title)
                    Spacer()
                }
            }
        }

        .navigationTitle("Details for \(list.title)")
        .toolbar {
            Button("Add Todo") {
                showAddTodoAlert.toggle()
            }
        }
        .alert("Add Todo", isPresented: $showAddTodoAlert) {
            TextField("Todo Title", text: $newTodoTitle)
            Button("Cancel", role: .cancel, action: {})
            Button("Create") {
                let todo = TodoItem(title: newTodoTitle)
                modelContext.insert(todo)
                list.items.append(todo)
            }
        }
        .id(list.id)


Here are the errors:

You don't say where the error apply, and you don't show the complete code. That makes it hard to analyse.

But it seems you have an extra or ill placed closing curly brackets in code. When you have an avalanche of errors that's first point to check. Updating indentation (ctrl-I) does help to find out the error.

struct TodoListView: View {
    @Environment(\.modelContext) private var modelContext
    @State var list: TodoList
    
    @State private var showAddTodoAlert: Bool = false
    @State private var newTodoTitle: String = ""
    
    var body: some View {
        List {
            Section("Todo") {
                ForEach(list.items.filter { $0.isDone == false }){ item in
                    HStack {
                        Button {
                            item.isDone.toggle()
                        }
                    }
                } label: {
                    Image(systemName: item.isDone ? "circle.fill" : "circle")
                }
                Text(item.title)
                Spacer()
            }
            // } // <<-- extra } here
            //} // <<-- extra } here
            
            Section("Done") {
                ForEach(list.items.filter { $0.isDone }){ item in
                    HStack {
                        Button {
                            item.isDone.toggle()
                        }
                    } label: {
                        Image(systemName: item.isDone ? "circle.fill" : "circle")
                    }
                    Text(item.title)
                    Spacer()
                }
            }
        }
        
        .navigationTitle("Details for \(list.title)")
        .toolbar {
            Button("Add Todo") {
                showAddTodoAlert.toggle()
            }
        }
        .alert("Add Todo", isPresented: $showAddTodoAlert) {
            TextField("Todo Title", text: $newTodoTitle)
            Button("Cancel", role: .cancel, action: {})
            Button("Create") {
                let todo = TodoItem(title: newTodoTitle)
                modelContext.insert(todo)
                list.items.append(todo)
            }
        }
        .id(list.id)
    } // <<-- missing } here
} // <<-- missing } here

Did that solve the issue ? If yes, don't forget to close the thread. If no, please explain.

Note: in several of your posts, you have curlay brace ill placed errors. A good way to detect is to perform automatic identation (ctrl-I)

Getting 17 errors while using SwiftData, Xcode 15 beta 8
 
 
Q