I am working on an application update. I have rewrote the application from the scratch and switched to magicalrecords for model controlling Heres my problem:
- I have created a new "newdatabase.xcdatamodel" file that contains an entity named "foo".
- At the first release of the app, i also had a "olddatabase.xcdatamodel" which also incloded an entity named "foo"
- When user installs the application from scratch theres no problem.
- If the user has a previous version of the app, his device has the "olddatabase.mom" file which also contains the old "foo" entity, so as you can imagine, the application crashed with the error:
Can't merge models with two different entities named 'foo''
So is it possible the detect and delete the old "olddatabase.mom" file before loading the new mom file?
i have tried the following code, and just as i thought, i have no permission on that folder :)
NSString *path = [[NSBundle mainBundle]pathForResource:@"olddatabase" ofType:@"mom"];
if(path){
NSError* error = nil;
NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager removeItemAtPath:path error:&error];
if(error)
NSLog(@"Error: %@",[error description]);
}
NSLog(@"path = %@",path);
I am starting think about changing my new "foo" entity name to "foo2" or something else, but i really am obsessed with using proper names for things that i use so i'd be glad to learn if there is a way to do it.
Thanks for reading and (probably) responding :)