Skip to content

Commit 5e9f2f5

Browse files
committed
多线程支持
解决多线程环境下的Crash问题
1 parent 498303d commit 5e9f2f5

File tree

4 files changed

+24
-19
lines changed

4 files changed

+24
-19
lines changed

MJExtension.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "MJExtension"
3-
s.version = "3.0.11"
3+
s.version = "3.0.12"
44
s.ios.deployment_target = '6.0'
55
s.osx.deployment_target = '10.8'
66
s.summary = "A fast and convenient conversion between JSON and model"

MJExtension/MJPropertyType.m

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ + (void)initialize
2222
+ (instancetype)cachedTypeWithCode:(NSString *)code
2323
{
2424
MJExtensionAssertParamNotNil2(code, nil);
25-
26-
MJPropertyType *type = types_[code];
27-
if (type == nil) {
28-
type = [[self alloc] init];
29-
type.code = code;
30-
types_[code] = type;
25+
@synchronized (self) {
26+
MJPropertyType *type = types_[code];
27+
if (type == nil) {
28+
type = [[self alloc] init];
29+
type.code = code;
30+
types_[code] = type;
31+
}
32+
return type;
3133
}
32-
return type;
3334
}
3435

3536
#pragma mark - 公共方法

MJExtension/NSObject+MJClass.m

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ + (void)load
3434

3535
+ (NSMutableDictionary *)dictForKey:(const void *)key
3636
{
37-
if (key == &MJAllowedPropertyNamesKey) return allowedPropertyNamesDict_;
38-
if (key == &MJIgnoredPropertyNamesKey) return ignoredPropertyNamesDict_;
39-
if (key == &MJAllowedCodingPropertyNamesKey) return allowedCodingPropertyNamesDict_;
40-
if (key == &MJIgnoredCodingPropertyNamesKey) return ignoredCodingPropertyNamesDict_;
41-
return nil;
37+
@synchronized (self) {
38+
if (key == &MJAllowedPropertyNamesKey) return allowedPropertyNamesDict_;
39+
if (key == &MJIgnoredPropertyNamesKey) return ignoredPropertyNamesDict_;
40+
if (key == &MJAllowedCodingPropertyNamesKey) return allowedCodingPropertyNamesDict_;
41+
if (key == &MJIgnoredCodingPropertyNamesKey) return ignoredCodingPropertyNamesDict_;
42+
return nil;
43+
}
4244
}
4345

4446
+ (void)mj_enumerateClasses:(MJClassesEnumeration)enumeration

MJExtension/NSObject+MJProperty.m

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ + (void)load
4444

4545
+ (NSMutableDictionary *)dictForKey:(const void *)key
4646
{
47-
if (key == &MJReplacedKeyFromPropertyNameKey) return replacedKeyFromPropertyNameDict_;
48-
if (key == &MJReplacedKeyFromPropertyName121Key) return replacedKeyFromPropertyName121Dict_;
49-
if (key == &MJNewValueFromOldValueKey) return newValueFromOldValueDict_;
50-
if (key == &MJObjectClassInArrayKey) return objectClassInArrayDict_;
51-
if (key == &MJCachedPropertiesKey) return cachedPropertiesDict_;
52-
return nil;
47+
@synchronized (self) {
48+
if (key == &MJReplacedKeyFromPropertyNameKey) return replacedKeyFromPropertyNameDict_;
49+
if (key == &MJReplacedKeyFromPropertyName121Key) return replacedKeyFromPropertyName121Dict_;
50+
if (key == &MJNewValueFromOldValueKey) return newValueFromOldValueDict_;
51+
if (key == &MJObjectClassInArrayKey) return objectClassInArrayDict_;
52+
if (key == &MJCachedPropertiesKey) return cachedPropertiesDict_;
53+
return nil;
54+
}
5355
}
5456

5557
#pragma mark - --私有方法--

0 commit comments

Comments
 (0)