Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Flush entity in core data

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 845
    Comment on it

    If you need to delete or flush all the data that exist in core data entity then use this method. Just pass the name of the Entity as a param to this method.

    -(void)flushEntity:(NSString*)entityName{
    
        NSFetchRequest *fetchAllObjects = [[NSFetchRequest alloc] init];
        [fetchAllObjects setEntity:[NSEntityDescription entityForName:entityName inManagedObjectContext:self.myContext]];
        [fetchAllObjects setIncludesPropertyValues:NO]; //only fetch the managedObjectID
    
        NSError *erors = nil;
        NSArray *allObjects = [self.myContext executeFetchRequest:fetchAllObjects error:&erors];
        // uncomment next line if you're NOT using ARC
        // [allObjects release];
        if (erors) {
            NSLog(@"Error occurred1");
        }else
            NSLog(@"Error occurred1");
    
        for (NSManagedObject *object in allObjects) {
            [self.myContext deleteObject:object];
        }
    }
    

    Happy Coding

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: