(BOOL)resetDatastore
{
[[self managedObjectContext] lock];
[[self managedObjectContext] reset];
NSPersistentStore *store = [[[self persistentStoreCoordinator] persistentStores] lastObject];
BOOL resetOk = NO;
if (store)
{
NSURL *storeUrl = store.URL;
NSError *error;
if ([[self persistentStoreCoordinator] removePersistentStore:store error:&error])
{
[[self persistentStoreCoordinator] release];
__persistentStoreCoordinator = nil;
[[self managedObjectContext] release];
__managedObjectContext = nil;
if (![[NSFileManager defaultManager] removeItemAtPath:storeUrl.path error:&error])
{
NSLog(@"\nresetDatastore. Error removing file of persistent store: %@",
[error localizedDescription]);
resetOk = NO;
}
else
{
//now recreate persistent store
[self persistentStoreCoordinator];
[[self managedObjectContext] unlock];
resetOk = YES;
}
}
else
{
NSLog(@"\nresetDatastore. Error removing persistent store: %@",
[error localizedDescription]);
resetOk = NO;
}
return resetOk;
}
else
{
NSLog(@"\nresetDatastore. Could not find the persistent store");
return resetOk;
}
}
2012年10月29日月曜日
CoreDataのデータを全て削除
登録:
コメントの投稿 (Atom)
0 件のコメント:
コメントを投稿