How To Fix CoreData: error: Failed to load mode model named ...

Hi. I have no clue what I am doing wrong or am i missing something else. I keep getting the error message

CoreData: error: Failed to load model named DMTideCity

Please see attached image for data model. My goal is just to load this but I dont know why I keep getting that error message.

struct TideDataController {
   
  static let shared = TideDataController()
  let cityContainer: NSPersistentContainer
   
  init() {
    print("init")
    cityContainer = NSPersistentContainer(name: "DMTideCity")
    print(cityContainer)
    cityContainer.loadPersistentStores { description, error in
      if let error {
        print("Core Data Citys failed to load: \(error.localizedDescription)")
      }
      else {
        print("Core Data Citys loaded")
      }
    }
  }
}

In my view, i declare a variable like this

let tideDataController = TideDataController.shared

So it never reaches the print(cityContainer) because of that error message.

Thoughts?

Answered by MobileTen in 741018022

Change  cityContainer = NSPersistentContainer(name: "DMTideCity") to cityContainer = NSPersistentContainer(name: "TideCityForeCast") or cityContainer = NSPersistentContainer(name: "TideForeCast")

Please read the Core data documentation for the do's and don'ts

Accepted Answer

Change  cityContainer = NSPersistentContainer(name: "DMTideCity") to cityContainer = NSPersistentContainer(name: "TideCityForeCast") or cityContainer = NSPersistentContainer(name: "TideForeCast")

Please read the Core data documentation for the do's and don'ts

How To Fix CoreData: error: Failed to load mode model named ...
 
 
Q