Delete object in Core Data
Its quite simple :)
[context deleteObject:favorisObj];
And the bad object is all gone.
Update
You'd just reverse it with something like this if you need a button to delete the object.
-(IBAction)removeFavoris:(id)sender {
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
[context deleteObject:favorisObj];
}
Don't forget to save the Context after you have deleted a NSManagedObject. So here is the general code;
NSManagedObjectContext * context = [self managedObjectContext];
[context deleteObject:objectToDelete];
NSError * error = nil;
if (![context save:&error])
{
NSLog(@"Error ! %@", error);
}
In your case it should have the snippet after the for loop.
for (NSManagedObject *managedObject in array) {
[moc2 deleteObject:managedObject];
}
NSError * error = nil;
if (![context save:&error])
{
NSLog(@"Error ! %@", error);
}