coreData删除整张表的方法

    YFF_AppDelegate *delegate = (YFF_AppDelegate *)[[UIApplication sharedApplication]delegate]; //这里需要引进项目的委托,是让全局managedObjectContext起作用

    NSManagedObjectContext *context = delegate.managedObjectContext;

    

    NSEntityDescription *description = [NSEntityDescription entityForName:@"VocaUnit" inManagedObjectContext:context]; // VocaUnit是数据表名字

    NSFetchRequest *request = [[NSFetchRequest alloc] init];

    [request setIncludesPropertyValues:NO];

    [request setEntity:description];


    NSError *error = nil;

    NSArray *datas = [context executeFetchRequest:request error:&error];

    if (!error && datas && [datas count])

    {

        for (NSManagedObject *obj in datas)

        {

            [context deleteObject:obj];

        }

        if (![context save:&error])

        {

            NSLog(@"error:%@",error);

        }

    }


原文地址:http://www.csdn123.com/html/blogs/20130906/65163.htm

你可能感兴趣的:(coredata,删除表)