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

Telnet lib and language choice for cross OS telnet client?

client telnet mud

I'm looking to start a MUD client application, which connects to a MUD hosted on a telnet server. The only thing important to me is that it runs painlessly and efficiently across any OS. Aside from

NSTextView does not receive string

osx cocoa

I am writing a basic text editor and need to implement a reading method. Since I am using NSDocument, I decide to override the method - (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName

fgets() getting skipped, how to clear user input?

c user-input fgets sscanf

I am using fgets() to get user input, and then I parse it into a double using sscanf(). Here is my example code:

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.