NSDictionary+Merge: Support overwriting empty
Support overwriting empty fields of NSNumber or NSString form with values from the merging dictionary. Correctly overwrite the value from the first dictionary with values from the second if the first contains empty strings or zeroed numbers. Signed-off-by: Christopher Snowhill <kode54@gmail.com>CQTexperiment
parent
a8c9f748c7
commit
67fcd2bb27
|
@ -11,6 +11,19 @@
|
|||
} else if([obj isKindOfClass:[NSDictionary class]]) {
|
||||
NSDictionary *newVal = [[dict1 objectForKey:key] dictionaryByMergingWith:(NSDictionary *)obj];
|
||||
[result setObject:newVal forKey:key];
|
||||
} else {
|
||||
BOOL isEmpty = NO;
|
||||
id objTarget = [dict1 objectForKey:key];
|
||||
if([objTarget isKindOfClass:[NSString class]]) {
|
||||
NSString *val = (NSString *)objTarget;
|
||||
isEmpty = [val length] == 0;
|
||||
} else if([objTarget isKindOfClass:[NSNumber class]]) {
|
||||
NSNumber *val = (NSNumber *)objTarget;
|
||||
isEmpty = [val isEqualTo:@(0)];
|
||||
}
|
||||
if(isEmpty) {
|
||||
[result setObject:obj forKey:key];
|
||||
}
|
||||
}
|
||||
}];
|
||||
|
||||
|
|
Loading…
Reference in New Issue