3

I'm trying to use CoreData but whenever I try to store an object, I have been getting the EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) error. What might be causing this error? As a side note, I did not initially create my project intending to use CoreData so CoreData was something I added onto my project later (I don't know if this might be what's causing the problem).

    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("repliaoutput", withExtension: "momd")!
        return NSManagedObjectModel(contentsOfURL: modelURL)! //this line is where the EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) error is
    }()
spotatoz
  • 151
  • 1
  • 1
  • 6

2 Answers2

1

Remove repliaoutput.xcdatamodel from your project tree, then drag and drop repliaoutput.xcdatamodeld (note the final "d") into your project. Clean, build and it should run like a charm.

rjobidon
  • 3,055
  • 3
  • 30
  • 36
0

Check if you are getting path in modelURL If you have created Core Data on later stage, create a new Data model named repliaoutput in the main project target and build again
New File -> iOS - Core Data - Data Model

HardikDG
  • 5,892
  • 2
  • 26
  • 55