0
我想刪除所有的對象,但我似乎無法使其工作。我知道這類問題還有其他問題,但它們沒有幫助。我想要的是刪除該方法中的部分和夾具實體中的所有對象。從另一種方法從NSManagedObjectContext刪除對象
- (void)refresh:(UIRefreshControl *)refreshControl {
[refreshControl endRefreshing];
}
這是我用另一種方法保存和獲取我的對象的地方。
NSManagedObjectContext *context = [self managedObjectContext];
for (int i=0; i <=fixtures.count-1; i++) {
fixture = [NSEntityDescription insertNewObjectForEntityForName:@"Fixture" inManagedObjectContext:context];
[fixture setValue:[NSString stringWithFormat:@"%@",[[fixtures objectAtIndex:i] objectForKey:@"date"]] forKey:@"date"];
[fixture setValue:[[fixtures objectAtIndex:i] objectForKey:@"time"] forKey:@"time"];
[fixture setValue:[[fixtures objectAtIndex:i] objectForKey:@"home"] forKey:@"home"];
[fixture setValue:[[fixtures objectAtIndex:i] objectForKey:@"away"] forKey:@"away"];
[fixture setValue:[[fixtures objectAtIndex:i] objectForKey:@"league"] forKey:@"league"];
}
for (int i=0; i <=sections.count-1; i++) {
lolSection = [NSEntityDescription insertNewObjectForEntityForName:@"Section" inManagedObjectContext:context];
[lolSection setValue:[NSString stringWithFormat:@"%@",[[sections objectAtIndex:i] objectForKey:@"date"]] forKey:@"date"];
}
NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Fixture"];
self.theFixtures = [[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy];
NSFetchRequest *fetchRequest2 = [[NSFetchRequest alloc] initWithEntityName:@"Section"];
self.theSection= [[managedObjectContext executeFetchRequest:fetchRequest2 error:nil] mutableCopy];
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"self" ascending:NO];
NSArray *descriptors = [NSArray arrayWithObject: descriptor];
NSArray* reverseTheArray = [[self.theSection valueForKey:@"date"] sortedArrayUsingDescriptors:descriptors];
reversedArray = [[reverseTheArray reverseObjectEnumerator] allObjects];