一开始,清除缓存做法,比如清除FMDB缓存,删除我自定义的文件夹就行,but
coredata,我们用这种思路删除。。。
程序瞬间爆炸,所以,我们得遍历出coredata每个表,逐个清空data
代码如下:
-(void)deleteAllData{
NSManagedObjectContext* cxt = [selfmanagedObjectContext];
NSManagedObjectModel* model = [selfmanagedObjectModel];
NSDictionary* entities = [modelentitiesByName];
NSArray* entityDescriptionArr = [entitiesallValues];
for(intcount =0;count
NSEntityDescription*entityDescription = entityDescriptionArr[count];
NSFetchRequest*request = [[NSFetchRequestalloc]init];
[requestsetEntity:entityDescription];
NSError*error =nil;
NSArray*listData = [cxtexecuteFetchRequest:requesterror:&error];
for(idrecordinlistData) {
[cxtdeleteObject:record];
}
}
NSError*savingError =nil;
if([cxtsave:&savingError]){
NSLog(@"删除数据成功");
}else{
NSLog(@"删除数据失败");
}
}
网友评论