Skip to content

Commit feffda9

Browse files
committed
Own deep mutable copy implementation
1 parent fdf6ace commit feffda9

2 files changed

Lines changed: 40 additions & 5 deletions

File tree

DSJSONSchemaValidation.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 = 'DSJSONSchemaValidation'
3-
s.version = '2.0.2'
3+
s.version = '2.0.3'
44
s.authors = {'Vlas Voloshin' => 'argentumko@gmail.com', 'Andrew Podkovyrin' => 'podkovyrin@gmail.com'}
55
s.homepage = 'https://github.com/dashevo/JSONSchemaValidation'
66
s.social_media_url = 'https://twitter.com/podkovyr'

DSJSONSchemaValidation/Categories/NSDictionary+DSJSONDeepMutableCopy.m

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,47 @@
1010

1111
NS_ASSUME_NONNULL_BEGIN
1212

13+
@interface NSArray (DSJSONDeepMutableCopyArray)
14+
15+
- (NSMutableArray *)ds_deepMutableCopy;
16+
17+
@end
18+
19+
@implementation NSArray (DSJSONDeepMutableCopyArray)
20+
21+
- (NSMutableArray *)ds_deepMutableCopy {
22+
NSMutableArray *mutableSelf = [NSMutableArray arrayWithCapacity:self.count];
23+
for (id object in self) {
24+
if ([object isKindOfClass:NSArray.class] || [object isKindOfClass:NSDictionary.class]) {
25+
[mutableSelf addObject:[(NSArray *)object ds_deepMutableCopy]];
26+
}
27+
else {
28+
[mutableSelf addObject:object];
29+
}
30+
}
31+
return mutableSelf;
32+
}
33+
34+
@end
35+
1336
@implementation NSDictionary (DSJSONDeepMutableCopy)
1437

15-
- (NSMutableDictionary *)ds_deepMutableCopy
16-
{
17-
NSMutableDictionary *mutableCopy = (NSMutableDictionary *)CFBridgingRelease(CFPropertyListCreateDeepCopy(kCFAllocatorDefault, (CFDictionaryRef)self, kCFPropertyListMutableContainers));
18-
return mutableCopy;
38+
- (NSMutableDictionary *)ds_deepMutableCopy {
39+
NSMutableDictionary *mutableSelf = [NSMutableDictionary dictionaryWithCapacity:self.count];
40+
for (id key in self) {
41+
id mutableKey = key;
42+
if ([key isKindOfClass:NSArray.class] || [key isKindOfClass:NSDictionary.class]) {
43+
mutableKey = [(NSDictionary *)key ds_deepMutableCopy];
44+
}
45+
46+
id mutableValue = self[key];
47+
if ([mutableValue isKindOfClass:NSArray.class] || [mutableValue isKindOfClass:NSDictionary.class]) {
48+
mutableValue = [(NSDictionary *)mutableValue ds_deepMutableCopy];
49+
}
50+
51+
mutableSelf[mutableKey] = mutableValue;
52+
}
53+
return mutableSelf;
1954
}
2055

2156
@end

0 commit comments

Comments
 (0)