[英]Core data delete objects
我在應用程序中使用核心數據。 當我使用[context deleteObject:obj]
刪除對象時,對象不會僅使用空字段刪除。 如何永久刪除對象? 提前致謝。 我使用表視圖,當該視圖中填充了核心數據中的數據時,有空行被刪除了。 這是代碼:
LNAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
self.context = [appDelegate managedObjectContext];
self.accounts = [[NSArray alloc] init];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"Accounts" inManagedObjectContext:self.context];
[fetchRequest setEntity:entity];
NSError *error;
self.accounts = [self.context executeFetchRequest:fetchRequest error:&error];
更改后確定要保存上下文嗎?
NSError *error = nil;
if(![self.managedObjectContext save:&error])
{
/*
//Handle error
*/
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}
另外,請確保您引用的是正確的上下文,因為可以有多個上下文。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.