Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Source/MMRecord/MMRecord.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#import "FBMMRecordTweakModel.h"
#endif

#import <objc/runtime.h>

static dispatch_group_t _mmrecord_request_group = nil;
static dispatch_semaphore_t _mmrecord_request_semaphore = nil;
static BOOL _mmrecord_batch_requests = NO;
Expand Down Expand Up @@ -87,6 +89,8 @@ + (MMRecordRequestState *)requestStateForURN:(NSString*)URN
// `NSEntityDescription` object for a given class name.
@interface NSManagedObjectContext (MMRecord)

@property BOOL shouldSkipValidation;

- (void)MMRecord_startObservingWithContext:(NSManagedObjectContext*)context;
- (void)MMRecord_stopObservingWithContext:(NSManagedObjectContext*)context;
- (NSEntityDescription*)MMRecord_entityForClass:(Class)managedObjectClass;
Expand Down Expand Up @@ -349,6 +353,7 @@ + (void)configureBackgroundContext:(NSManagedObjectContext *)backgroundContext
if (options.automaticallyPersistsRecords == NO) {
if ([backgroundContext respondsToSelector:@selector(setParentContext:)]) {
[backgroundContext setParentContext:mainContext];
backgroundContext.shouldSkipValidation = YES;
}
} else {
[backgroundContext setPersistentStoreCoordinator:mainStoreCoordinator];
Expand Down Expand Up @@ -685,6 +690,10 @@ + (BOOL)validateSetUpForStartRequest {
return YES;
}

-(BOOL)validateValue:(__autoreleasing id *)value forKey:(NSString *)key error:(NSError *__autoreleasing *)error {
if (self.managedObjectContext.shouldSkipValidation) return YES;
return [super validateValue:value forKey:key error:error];
}

#pragma mark - Parsing Helper Methods

Expand Down Expand Up @@ -1048,6 +1057,16 @@ - (NSEntityDescription *)MMRecord_entityForClass:(Class)managedObjectClass {
return nil;
}

#pragma mark - Skip validation on working context

-(BOOL)shouldSkipValidation {
return [objc_getAssociatedObject(self, @selector(shouldSkipValidation)) boolValue];
}

-(void)setShouldSkipValidation:(BOOL)shouldSkipValidation {
objc_setAssociatedObject(self, @selector(shouldSkipValidation), @(shouldSkipValidation), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

@end


Expand Down