一:操作流程
- 先查询得到某条要删除的数据
- 然后删除某记录
二:演示代码
//删除 - (void)deleteThePersonData { NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; [fetchRequest setEntity:[NSEntityDescription entityForName:@"Entity" inManagedObjectContext:self.appDelegate.managedObjectContext]]; //删除谁的条件在这里配置; NSString *theName = @"abc"; [fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"name==%@", theName]]; NSError* error = nil; NSArray* results = [self.appDelegate.managedObjectContext executeFetchRequest:fetchRequest error:&error]; if ([results count] > 0) { [self.appDelegate.managedObjectContext deleteObject:[results objectAtIndex:0]]; NSLog(@"%@",results); } }
比如:上述代码,删除 name=abc 的记录
参考:http://stackoverflow.com/questions/10482311/delete-an-object-in-core-data