Skip to content

Instantly share code, notes, and snippets.

@Daij-Djan
Created May 15, 2013 12:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Daij-Djan/5583789 to your computer and use it in GitHub Desktop.
Save Daij-Djan/5583789 to your computer and use it in GitHub Desktop.
NSManagedObjectContext+SafeMerge swizzles -mergeChangesFromContextDidSaveNotification and wraps it in a @Try and catch => this isn't nice but sometimes merging fails for no good reason and this catches the exception there -- needed for GoogleMaps 1.2
#import <CoreData/CoreData.h>
@interface NSManagedObjectContext (SafeMerge)
@end
#import "NSManagedObjectContext+SafeMerge.h"
#import "NSObject+MethodSwizzle.h" //helpers for swizzeling
@implementation NSManagedObjectContext (SafeMerge)
+ (void)load {
SEL originalSelector = @selector(mergeChangesFromContextDidSaveNotification:);
SEL overrideSelector = @selector(mergeChangesFromContextDidSaveNotification_xchg:);
[self swizzleInstanceMethodWithSelector:originalSelector withSelector:overrideSelector];
}
- (void)mergeChangesFromContextDidSaveNotification_xchg:(NSNotification*)note {
@try {
[self mergeChangesFromContextDidSaveNotification_xchg:note]; //swizzled original
}
@catch (NSException *exception) {
NSLog(@"failed to merge, skip: %@", exception);
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment