diff --git a/Realm+JSON/RLMObject+JSON.m b/Realm+JSON/RLMObject+JSON.m index cb37a55..93acf40 100644 --- a/Realm+JSON/RLMObject+JSON.m +++ b/Realm+JSON/RLMObject+JSON.m @@ -294,19 +294,20 @@ + (NSDictionary *)mc_inboundMapping { dispatch_once(&onceToken, ^{ mappingForClassName = [NSMutableDictionary dictionary]; }); - - NSDictionary *mapping = mappingForClassName[[self className]]; - if (!mapping) { - SEL selector = NSSelectorFromString(@"JSONInboundMappingDictionary"); - if ([self respondsToSelector:selector]) { - mapping = MCValueFromInvocation(self, selector); - } - else { - mapping = [self mc_defaultInboundMapping]; - } - mappingForClassName[[self className]] = mapping; - } - return mapping; + @synchronized(mappingForClassName) { + NSDictionary *mapping = mappingForClassName[[self className]]; + if (!mapping) { + SEL selector = NSSelectorFromString(@"JSONInboundMappingDictionary"); + if ([self respondsToSelector:selector]) { + mapping = MCValueFromInvocation(self, selector); + } + else { + mapping = [self mc_defaultInboundMapping]; + } + mappingForClassName[[self className]] = mapping; + } + return mapping; + } } + (NSDictionary *)mc_outboundMapping { @@ -316,18 +317,20 @@ + (NSDictionary *)mc_outboundMapping { mappingForClassName = [NSMutableDictionary dictionary]; }); - NSDictionary *mapping = mappingForClassName[[self className]]; - if (!mapping) { - SEL selector = NSSelectorFromString(@"JSONOutboundMappingDictionary"); - if ([self respondsToSelector:selector]) { - mapping = MCValueFromInvocation(self, selector); - } - else { - mapping = [self mc_defaultOutboundMapping]; - } - mappingForClassName[[self className]] = mapping; - } - return mapping; + @synchronized(mappingForClassName) { + NSDictionary *mapping = mappingForClassName[[self className]]; + if (!mapping) { + SEL selector = NSSelectorFromString(@"JSONOutboundMappingDictionary"); + if ([self respondsToSelector:selector]) { + mapping = MCValueFromInvocation(self, selector); + } + else { + mapping = [self mc_defaultOutboundMapping]; + } + mappingForClassName[[self className]] = mapping; + } + return mapping; + } } + (RLMProperty *)mc_propertyForPropertyKey:(NSString *)key { @@ -349,12 +352,14 @@ + (Class)mc_classForPropertyKey:(NSString *)key { set = [NSCharacterSet characterSetWithCharactersInString:@"\"<"]; }); - NSString *string; - NSScanner *scanner = [NSScanner scannerWithString:attributes]; - scanner.charactersToBeSkipped = set; - [scanner scanUpToCharactersFromSet:set intoString:NULL]; - [scanner scanUpToCharactersFromSet:set intoString:&string]; - return NSClassFromString(string); + @synchronized(set) { + NSString *string; + NSScanner *scanner = [NSScanner scannerWithString:attributes]; + scanner.charactersToBeSkipped = set; + [scanner scanUpToCharactersFromSet:set intoString:NULL]; + [scanner scanUpToCharactersFromSet:set intoString:&string]; + return NSClassFromString(string); + } } return nil; }