2

I am attempting to rename a project in XCode7. After renaming it, it compiles fine, but I am getting a runtime error in this code block:

lazy var managedObjectModel: NSManagedObjectModel = {
    // The managed object model for the application. This property is not optional. It is a fatal error for the application not to be able to find and load its model.
    let modelURL = NSBundle.mainBundle().URLForResource("Test File", withExtension: "momd")!
    return NSManagedObjectModel(contentsOfURL: modelURL)!
}()

The exception that I'm getting is:

UpDown Count[6149:4086716] CoreData: Failed to load NSManagedObjectModel with URL 'file:///Users/Scott/Library/Developer/CoreSimulator/Devices/C66F52A5-3979-4D8D-A80D-337FDDCFDB29/data/Containers/Bundle/Application/B4D6F673-6EA9-446D-B29E-F769EAC33B38/Test%20File.app/Test%20File.momd/' fatal error: unexpectedly found nil while unwrapping an Optional value

I have tried resetting the simulator, and it did nothing.

I've renamed projects before, and had no problems. This is the first one that I've tried to rename that has core data.

Scott Kilbourn
  • 1,545
  • 6
  • 18
  • 40
  • Have you verified that `Test File.momd` exists in the app bundle? – Tom Harrington Nov 22 '15 at 04:51
  • I don't see it. I drilled down to the folder indicated in the exception, and there's not much there. Thing is, when I rename the project back to its original name, everything starts working normally. – Scott Kilbourn Nov 22 '15 at 04:55
  • check the error link is there your previous project name is placed? – Kishore Kumar Nov 22 '15 at 05:04
  • When I look at NSBundle.mainBundle, I see the same path that I can drill down to. And within that path, I see a file named Test File.app. I also checked it when I rename to the original file name, and it is the same deal with a .app file. The only difference is that it fails on let modelURL = NSBundle.mainBundle().URLForResource("Test File", withExtension: "momd")! after I've renamed the project. I just figured out how to look inside the .app file. There is indeed a file named Test File.momd within it. – Scott Kilbourn Nov 22 '15 at 05:06
  • When comparing between the .app file with the original name and the .app file with the new name, the only difference is that there is no .omo file. The .omo file exists with the original name only. – Scott Kilbourn Nov 22 '15 at 05:20
  • 2
    http://stackoverflow.com/questions/4536414/cant-find-momd-file-core-data-problems check this @ScottKilbourn – Kishore Kumar Nov 22 '15 at 05:20
  • Thank you @KishoreKumar. The answer was in that thread. I had to create a new data model. As soon as I did that, it all started working again. – Scott Kilbourn Nov 22 '15 at 05:44
  • wow fine @ScottKilbourn............. – Kishore Kumar Nov 22 '15 at 07:21

0 Answers0