我正在尝试删除一个核心数据实体,无论我使用什么删除规则,它都不起作用。它根本不做任何事情。
我正在使用 Firefox 的 Sqlite 插件来浏览核心数据数据库,并且在删除代码运行后我可以看到那里的所有行。
我的删除代码如下所示
+(void)deleteCustomerWithID:(int)customerid inManagedObjectContext:(NSManagedObjectContext *)context
{
Customer *customer = nil;
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Customer"];
request.predicate = [NSPredicate predicateWithFormat:@"id = %d", customerid];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"organization" ascending:YES];
request.sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
NSError *error = nil;
NSArray *customers = [context executeFetchRequest:request error:&error];
if (!customers || ([customers count] > 1)) {
// handle error
} else if (![customers count]) {
// customer not found
} else {
customer = [customers lastObject];
[context deleteObject:customer];
NSError *error;
if(![context save:&error]){
NSLog(@"Unresolved error series %@, %@", error, [error userInfo]);
}
}
}
任何想法我做错了什么?