下面的代碼不會刪除實體。控制檯上顯示「刪除成功」消息,因此找到該實體。我使用的所有其他操作都成功。無法使用RestKit從核心數據中刪除實體0.20
我正在使用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);
}
}
爲什麼這個刪除操作不成功,以及使其工作的解決方案是什麼。
刪除它後,你在哪裏看到實例? – 2013-02-26 19:22:00
我在模擬器中的* .sqlite文件上使用第三方工具「Base」。我可以使用該工具刪除實體。 – zaph 2013-02-26 22:08:40
我實際上在想,問題的症狀是什麼,以及什麼時候發生。你說你在刪除數據方面有問題,所以你什麼時候看到你認爲已經刪除的項目? – 2013-02-26 22:31:07