CoreData: EXC_BAD_INSTRUCTION Error when trying to load an array from a fetch request

I am currently making a Course/Homework Tracker App that tracks your classes. I have a tab that displays the courses that the user has created. When the user first uses the app, however, they do not have any courses saved, so this tab is empty.

Code Block import SwiftUI
import CoreData
struct MyHabits: View {
  @State var addCategory = false;
  @State var editCategory = false;
   
   
  @State var categoryToEdit : Category?
  @State var title : String
  @State var date : String
   
  @FetchRequest(entity: Category.entity(),
         sortDescriptors: [
           NSSortDescriptor(keyPath: \Category.title, ascending: true)
         ], animation: .spring()
  )
   
  var results: FetchedResults<Category>
  @Environment(\.managedObjectContext) var context
...
LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 0), count: 2), spacing: 20) {
             
            if results.count == 0 {
              Text("No Categories")
                .font(.title)
                .fontWeight(.heavy)
            } else {
     
            ForEach(results, id: \.self) { category in ...
// error occurs here, with the "results" underlined

Code Block import SwiftUI
refrence....
@main
struct habit_tracker_01App: App {
  let persistenceController = PersistenceController.shared
   
  var body: some Scene {
    WindowGroup {
      NavigationBar()
       
    }
  }
}




However, I am currently getting an error when I use ForEach loop to display empty results.

The error: Thread 1: EXCBADINSTRUCTION (code=EXCI386INVOP, subcode=0x0) How do I go about fixing this problem?

CoreData: EXC_BAD_INSTRUCTION Error when trying to load an array from a fetch request
 
 
Q