-
Notifications
You must be signed in to change notification settings - Fork 84
/
NSArray_DeepMutableCopy.m
39 lines (30 loc) · 988 Bytes
/
NSArray_DeepMutableCopy.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
// NSArray_DeepMutableCopy.m
//
// Created by Matt Gemmell on 02/05/2008.
// Copyright 2008 Instinctive Code. All rights reserved.
//
#import "NSArray_DeepMutableCopy.h"
@implementation NSArray (DeepMutableCopy)
- (NSMutableArray *)deepMutableCopy
{
NSMutableArray *newArray;
NSUInteger index, count;
count = [self count];
newArray = [[NSMutableArray alloc] initWithCapacity:count];
for (index = 0; index < count; index++) {
id anObject;
anObject = [self objectAtIndex:index];
if ([anObject respondsToSelector:@selector(deepMutableCopy)]) {
anObject = [anObject deepMutableCopy];
[newArray addObject:anObject];
} else if ([anObject respondsToSelector:@selector(mutableCopyWithZone:)]) {
anObject = [anObject mutableCopyWithZone:nil];
[newArray addObject:anObject];
} else {
[newArray addObject:anObject];
}
}
return newArray;
}
@end