core-dataios8nspersistentstore

Why is NSPersistentStoreCoordinator not recognizing my managed object model?


I am trying to create a CoreData store with iCloud. Following the example code in iCloud Programming Guide for Core Data, I have this piece of code:

    NSPersistentStoreCoordinator *coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: salonbook.xcdatamodeld];

This is the image of my managed object model

enter image description here

I'm getting an error: Use of undeclared identifier 'salonbook'.

Why?


Solution

  • You're getting the error because you're telling it to look for a variable named salonbook, which is not declared. You need to pass a reference to an NSManagedObjectModel instance here. Commonly that means you'd use self.managedObjectModel, but that really depends on the rest of your code. The steps need to be:

    1. Create an NSManagedObjectModel instance from the model file
    2. Create an NSPersistentStoreCoordinator using that model object.