Q:

Accidently deleted XCDataModel - Application now throws NSInvalidArgumentException - iPhone

I accidentally deleted my core data model file, I then tried to re-add it, but now my application throws the following:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Cannot create an NSPersistentStoreCoordinator with a nil model'
*** First throw call stack:
(0x1ef6022 0x186ecd6 0x1593a75 0x3021 0x2cea 0x34b0 0x26e5 0x6f0386 0x6f1274 0x700183 0x700c38 0x6f4634 0x2089ef5 0x1eca195 0x1e2eff2 0x1e2d8da 0x1e2cd84 0x1e2cc9b 0x6f0c65 0x6f2626 0x22ed 0x2255)
terminate called throwing an exception(lldb)

Can anyone explain the steps I need to take to get my app working again?
Cheers,
Tysin

A:

Though obviously one should be using some form of source control, this was a small project so I didn't create a repository.  For those in the same boat the following solved my problem:
In the method:
// Returns the managed object model for the application.
// If the model doesn't already exist, it is created from the application's model.
- (NSManagedObjectModel *)managedObjectModel
{
    if (_managedObjectModel != nil) {
        return _managedObjectModel;
    }
    NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"AppName" withExtension:@"momd"];
    _managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
    return _managedObjectModel;
}

I changed the line:
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"AppName" withExtension:@"momd"];

to:
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"AppName" withExtension:@"momd"];

I just removed the 'd' from the model file extension and everything worked.

