下面的代码不会删除实体。控制台上会显示“删除成功”消息,以便找到实体。我使用的所有其他操作都成功。
我正在使用 RestKit 0.20。
NSManagedObjectContext *context = [RKManagedObjectStore defaultStore].mainQueueManagedObjectContext;
NSError *error = nil;
NSFetchRequest * fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity: [NSEntityDescription entityForName:@"Auction" inManagedObjectContext:context]];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"AuctionID = %d", auctionID];
[fetchRequest setPredicate:predicate];
NSArray *result = [context executeFetchRequest:fetchRequest error:&error];
if(result.count) {
Auction *block = result[0];
[context deleteObject:block];
BOOL status = [context save:&error];
if (status == NO) {
NSLog(@"delete falied for AuctionID:%d, error: %@", auctionID, error);
}
else {
[context processPendingChanges];
NSLog(@"delete was successful for AuctionID:%d", auctionID);
}
}
为什么此删除操作可能不成功,以及使它工作的解决方案是什么。