Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 75 lines (58 sloc) 1.735 kb
24dca8d @uliwitness Deep copy categories for NSArray, NSSet, and NSDictionary.
authored
1 //
2 // NSArray+DeepCopy.m
3 // UKSyntaxColoredDocument
4 //
5 // Created by Uli Kusterer on Tue May 18 2004.
6 // Copyright (c) 2004 M. Uli Kusterer. All rights reserved.
7 //
8
9 // -----------------------------------------------------------------------------
10 // Headers:
11 // -----------------------------------------------------------------------------
12
13 #import "NSArray+DeepCopy.h"
14
15
16 @implementation NSArray (UKDeepCopy)
17
18 -(NSArray*) deepCopy
19 {
20 NSMutableArray * theArray = [NSMutableArray arrayWithCapacity: [self count]];
21 NSEnumerator * enny = [self objectEnumerator];
22 id currObj = nil;
23
24 while(( currObj = [enny nextObject] ))
25 {
26 if( [currObj respondsToSelector: @selector(deepCopy)] )
27 currObj = [[currObj deepCopy] autorelease];
28 else
29 currObj = [[currObj copy] autorelease];
30 [theArray addObject: currObj];
31 }
32
33 return theArray;
34 }
35
36
37 -(NSMutableArray*) deepMutableContainerCopy
38 {
39 NSMutableArray * theArray = [NSMutableArray array];
40 NSEnumerator * enny = [self objectEnumerator];
41 id currObj = nil;
42
43 while(( currObj = [enny nextObject] ))
44 {
45 if( [currObj respondsToSelector: @selector(deepCopy)] )
46 currObj = [[currObj deepMutableContainerCopy] autorelease];
47 else
48 currObj = [[currObj copy] autorelease];
49 [theArray addObject: currObj];
50 }
51
52 return theArray;
53 }
54
55
56 -(NSMutableArray*) deepMutableCopy
57 {
58 NSMutableArray * theArray = [NSMutableArray array];
59 NSEnumerator * enny = [self objectEnumerator];
60 id currObj = nil;
61
62 while(( currObj = [enny nextObject] ))
63 {
64 if( [currObj respondsToSelector: @selector(deepCopy)] )
65 currObj = [[currObj deepMutableCopy] autorelease];
66 else
67 currObj = [[currObj mutableCopy] autorelease];
68 [theArray addObject: currObj];
69 }
70
71 return theArray;
72 }
73
74 @end
Something went wrong with that request. Please try again.