File tree Expand file tree Collapse file tree 2 files changed +11
-5
lines changed
KVC Validation Pattern/KVC Validation Pattern/Model Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change 15
15
@property (nonatomic , strong , readonly ) NSString *dictionaryKey;
16
16
@property (nonatomic , readonly , strong ) NSDictionary *undefinedKeys;
17
17
18
- - (id )initWithDictionary : (NSDictionary *)jsonObject ;
18
+ - (id )initWithDictionary : (NSDictionary *)dictionary ;
19
19
20
20
+ (NSString *)calculateClassName ;
21
21
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ typedef NS_ENUM(NSUInteger, CTCPropertyType){
30
30
};
31
31
32
32
@implementation CTCBaseModel {
33
-
33
+ dispatch_once_t keyToken;
34
34
}
35
35
static NSMutableDictionary *modelProperties;
36
36
static dispatch_once_t onceToken;
@@ -49,15 +49,21 @@ + (void)initialize {
49
49
[modelProperties setObject: translateNameDict forKey: [self calculateClassName ]];
50
50
}
51
51
52
- - (id )initWithDictionary : (NSDictionary *)jsonObject {
52
+ - (id )initWithDictionary : (NSDictionary *)dictionary {
53
53
self = [self init ];
54
54
if (self){
55
- _dictionaryKey = [[self class ] calculateClassName ];
56
- [self setValuesForKeysWithDictionary: jsonObject];
55
+ [self setValuesForKeysWithDictionary: dictionary];
57
56
}
58
57
return self;
59
58
}
60
59
60
+ - (NSString *)dictionaryKey {
61
+ dispatch_once (&keyToken, ^{
62
+ _dictionaryKey = [[self class ] calculateClassName ];
63
+ });
64
+ return _dictionaryKey;
65
+ }
66
+
61
67
#pragma mark - KVC methods
62
68
63
69
- (void )setValue : (id )value forKey : (NSString *)key {
You can’t perform that action at this time.
0 commit comments