2016-07-26 3 views

答えて

0

ご希望の場合はお手数ですが、

NSString* aType = @"History"; 
NSString *tp = @"Dhaka"; 

NSFetchRequest * request = [[NSFetchRequest alloc] init]; 
[request setEntity:[NSEntityDescription entityForName:aType inManagedObjectContext:self.managedObjectContext]]; 
NSPredicate* predicate = [NSPredicate predicateWithFormat:@"(type == %@)",tp ]; //where type is the attribute 
[request setPredicate:predicate]; 
NSArray* ar = [self.managedObjectContext executeFetchRequest:request error:nil]; 
NSLog(@"@@@@@@@@@@@@@ Data from DB : %@",ar); 
for(id anObj in ar){ 
    [managedObjectContext deleteObject:anObj]; 
} 
[self.managedObjectContext save:nil]; 

predicate=nil; 
0

これを試してみてください。

objAppDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; 
    NSManagedObjectContext *context = [objAppDelegate managedObjectContext]; 
    NSFetchRequest *request = [[NSFetchRequest alloc]initWithEntityName:@"History"]; 
    NSArray *recordArray =[[NSArray alloc]initWithArray:[context executeFetchRequest:request error:nil]]; 
    objDataClass = [recordArray objectAtIndex:0]; // here objDataClass is a instance of DataClass derived from NSObject which define column name 
    [context deleteObject:objDataClass]; // Delete particular data with index 

    if ([context hasChanges]) 
    { 
     [context save:nil]; 
    } 
    else 
    { 
     NSLog(@"Object Deleted....."); 
    } 

が、それはあなたを助けることを願っています。 :)