mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-25 13:25:36 +08:00
Added helper methods for deleting managed object stores
This commit is contained in:
@@ -74,6 +74,25 @@ extern NSString* const RKManagedObjectStoreDidFailSaveNotification;
|
||||
+ (RKManagedObjectStore *)defaultObjectStore;
|
||||
+ (void)setDefaultObjectStore:(RKManagedObjectStore *)objectStore;
|
||||
|
||||
///-----------------------------------------------------------------------------
|
||||
/// @name Deleting Store Files
|
||||
///-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
Deletes the SQLite file backing an RKManagedObjectStore instance at a given path.
|
||||
|
||||
@param path The complete path to the store file to delete.
|
||||
*/
|
||||
+ (void)deleteStoreAtPath:(NSString *)path;
|
||||
|
||||
/**
|
||||
Deletes the SQLite file backing an RKManagedObjectStore instance with a given
|
||||
filename within the application data directory.
|
||||
|
||||
@param filename The name of the file within the application data directory backing a managed object store.
|
||||
*/
|
||||
+ (void)deleteStoreInApplicationDataDirectoryWithFilename:(NSString *)filename;
|
||||
|
||||
///-----------------------------------------------------------------------------
|
||||
/// @name Initializing an Object Store
|
||||
///-----------------------------------------------------------------------------
|
||||
|
||||
@@ -72,6 +72,25 @@ static RKManagedObjectStore *defaultObjectStore = nil;
|
||||
[NSManagedObjectContext setDefaultContext:objectStore.primaryManagedObjectContext];
|
||||
}
|
||||
|
||||
+ (void)deleteStoreAtPath:(NSString *)path
|
||||
{
|
||||
NSURL* storeURL = [NSURL fileURLWithPath:path];
|
||||
NSError* error = nil;
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:storeURL.path]) {
|
||||
if (! [[NSFileManager defaultManager] removeItemAtPath:storeURL.path error:&error]) {
|
||||
NSAssert(NO, @"Managed object store failed to delete persistent store : %@", error);
|
||||
}
|
||||
} else {
|
||||
RKLogWarning(@"Asked to delete persistent store but no store file exists at path: %@", storeURL.path);
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)deleteStoreInApplicationDataDirectoryWithFilename:(NSString *)filename
|
||||
{
|
||||
NSString *path = [[RKDirectory applicationDataDirectory] stringByAppendingPathComponent:filename];
|
||||
[self deleteStoreAtPath:path];
|
||||
}
|
||||
|
||||
+ (RKManagedObjectStore*)objectStoreWithStoreFilename:(NSString*)storeFilename {
|
||||
return [self objectStoreWithStoreFilename:storeFilename usingSeedDatabaseName:nil managedObjectModel:nil delegate:nil];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user