From 780a49c12cfc84f342684dba5bc0df50d9ce2e19 Mon Sep 17 00:00:00 2001 From: Luke Stringer Date: Mon, 22 Jun 2015 16:07:55 +0100 Subject: [PATCH] Use NSAssert to check MOC saves without errors in operations. When the context does not successfully save from within an operation then the error is made available from the error property. However recovering from an error once the operation has finished is next to impossible as you do not have access to the context that failed. Therefore is it better to just hard crash and fix the bug when you know the save failed. --- Classes/shared/SQKCoreDataOperation/SQKCoreDataOperation.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Classes/shared/SQKCoreDataOperation/SQKCoreDataOperation.m b/Classes/shared/SQKCoreDataOperation/SQKCoreDataOperation.m index fa7c77b..2428444 100644 --- a/Classes/shared/SQKCoreDataOperation/SQKCoreDataOperation.m +++ b/Classes/shared/SQKCoreDataOperation/SQKCoreDataOperation.m @@ -101,6 +101,9 @@ - (void)completeOperationBySavingContext:(NSManagedObjectContext *)managedObject NSError *error = nil; [managedObjectContext save:&error]; + + NSAssert(error == nil, @"Save errored"); + [self addError:error]; } }