MagicalRecord: Remove entire data and setup core data stack again

For every app update, I would like to wipe my entire Core Data database completely and then set it up again. I have not been successful in doing so. I have tried various things, this seems to be the closest I have come. I found several SO posts, but none of the solutions have worked for my purposes.

I am using MagicalRecord, which provides several short hand methods for obtain various objects. Here's my code:

if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"buildVersion"] intValue] < [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] intValue]) {
    NSPersistentStore *store = [NSPersistentStore defaultPersistentStore];
    NSError *error;
    NSURL *storeURL = [NSPersistentStore defaultLocalStoreUrl];
    NSPersistentStoreCoordinator *storeCoordinator = [NSPersistentStoreCoordinator defaultStoreCoordinator];
    [storeCoordinator removePersistentStore:store error:&error];
    [[NSFileManager defaultManager] removeItemAtPath:storeURL.path error:&error];
    [[NSUserDefaults standardUserDefaults] setObject:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] forKey:@"buildVersion"];

[MagicalRecord setupCoreDataStack];


There is a NSPersistentStore+MagicalRecord category which allows you to get the URL for the persistent store:

+ (NSURL *) MR_urlForStoreName:(NSString *)storeFileName;

You can use the URL from this call to delete the persistent store SQLite db using NSFileManager.

Need Your Help

Update coordinates every 5 secs by sending Post data to mysql - Android

android mysql gps http-post google-maps-api-2

I m totally a newbie in Android Programming, and would like to develop an app which send my realtime location coordinates from google map to MySql every 5 seconds. The problem is i dont know where ...

CSS3 Transform Scale and CSS3 experience

html css3

Please in the comments bellow you can or you must describe what i did wrong or what should know before doing something with css3.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.