我需要为我的核心数据创建一个方法。此方法应检查实体Section
和Fixture
中是否有任何结果。如果有则删除所有og中的对象。
我该怎么做?我试过这个,但什么也没做。
NSManagedObjectContext *context = [self managedObjectContext];
NSManagedObject *numberOfFixtures = [NSEntityDescription
insertNewObjectForEntityForName:@"Fixture"
inManagedObjectContext:context];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Fixture" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
self.theFixtures = [[context executeFetchRequest:fetchRequest error:nil] mutableCopy];
for (numberOfFixtures *fixture in self.theFixtures) {
[context deleteObject:fixture];
}
NSError *error;
[context save:&error];
答案 0 :(得分:1)
试试这个,
NSManagedObjectContext *context = [self managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Fixture" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
self.theFixtures = [[context executeFetchRequest:fetchRequest error:nil] mutableCopy];
for (NSManagedObject *fixture in self.theFixtures) {
[context deleteObject:fixture];
}
NSError *error;
[context save:&error];