File tree Expand file tree Collapse file tree 3 files changed +22
-4
lines changed Expand file tree Collapse file tree 3 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,16 @@ You should specify the inbound and outbound JSON mapping on your `RLMObject` sub
85
85
};
86
86
}
87
87
88
+ JSON preprocessing can be done by implementing ` jsonPreprocessing: ` static method:
89
+
90
+ ``` ObjC
91
+ - (NSDictionary *)jsonPreprocessing:(NSDictionary *)dictionary {
92
+ NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithDictionary:dictionary];
93
+ dict[@"releaseCount"] = @(0);
94
+ return dict.copy;
95
+ }
96
+ ```
97
+
88
98
Leaving out either one of the above will result in a mapping that assumes camelCase for your properties which map to snake_case for the JSON equivalents.
89
99
90
100
As you can do with Mantle, you can specify ` NSValueTransformers ` for your properties:
Original file line number Diff line number Diff line change 1
1
Pod ::Spec . new do |s |
2
2
s . name = 'Realm+JSON'
3
- s . version = '0.2.14 '
3
+ s . version = '0.2.16 '
4
4
s . ios . deployment_target = '7.0'
5
5
s . osx . deployment_target = '10.9'
6
6
s . watchos . deployment_target = '2.0'
Original file line number Diff line number Diff line change @@ -156,16 +156,24 @@ - (void)removeFromRealm {
156
156
157
157
#pragma mark - Private
158
158
159
- + (id )mc_createObjectFromJSONDictionary : (NSDictionary *)dictionary {
159
+ + (id )mc_createObjectFromJSONDictionary : (NSDictionary *)origDict {
160
160
NSMutableDictionary *result = [NSMutableDictionary dictionary ];
161
161
NSDictionary *mapping = [[self class ] mc_inboundMapping ];
162
162
163
+ NSDictionary *dictionary;
164
+ SEL preprocessingSel = NSSelectorFromString (@" preprocessedJSON:" );
165
+ if ([self respondsToSelector: preprocessingSel]) {
166
+ dictionary = [self performSelector: preprocessingSel withObject: origDict];
167
+ } else {
168
+ dictionary = origDict;
169
+ }
170
+
163
171
for (NSString *dictionaryKeyPath in mapping) {
164
172
NSString *objectKeyPath = mapping[dictionaryKeyPath];
165
-
173
+
166
174
id value = [dictionary valueForKeyPath: dictionaryKeyPath];
167
175
168
- if (value) {
176
+ if (value) {
169
177
Class propertyClass = [[self class ] mc_classForPropertyKey: objectKeyPath];
170
178
171
179
NSValueTransformer *transformer = [[self class ] mc_transformerForPropertyKey: objectKeyPath];
You can’t perform that action at this time.
0 commit comments