Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 93 lines (77 sloc) 2.62 kb
24dca8df »
2010-02-23 Deep copy categories for NSArray, NSSet, and NSDictionary.
1 //
2 // NSArray+DeepCopy.m
3 // UKSyntaxColoredDocument
4 //
5 // Created by Uli Kusterer on Tue May 18 2004.
720b0e7b »
2010-03-04 Added licensing information to the source files.
6 // Copyright (c) 2004 M. Uli Kusterer.
7 //
8 // This software is provided 'as-is', without any express or implied
9 // warranty. In no event will the authors be held liable for any damages
10 // arising from the use of this software.
11 //
12 // Permission is granted to anyone to use this software for any purpose,
13 // including commercial applications, and to alter it and redistribute it
14 // freely, subject to the following restrictions:
15 //
16 // 1. The origin of this software must not be misrepresented; you must not
17 // claim that you wrote the original software. If you use this software
18 // in a product, an acknowledgment in the product documentation would be
19 // appreciated but is not required.
20 //
21 // 2. Altered source versions must be plainly marked as such, and must not be
22 // misrepresented as being the original software.
23 //
24 // 3. This notice may not be removed or altered from any source
25 // distribution.
24dca8df »
2010-02-23 Deep copy categories for NSArray, NSSet, and NSDictionary.
26 //
27
28 // -----------------------------------------------------------------------------
29 // Headers:
30 // -----------------------------------------------------------------------------
31
32 #import "NSArray+DeepCopy.h"
33
34
35 @implementation NSArray (UKDeepCopy)
36
37 -(NSArray*) deepCopy
38 {
2d7bd235 »
2010-02-23 Err... adhere to Cocoa's memory management contract, don't screw the …
39 NSMutableArray * theArray = [[NSMutableArray alloc] initWithCapacity: [self count]];
24dca8df »
2010-02-23 Deep copy categories for NSArray, NSSet, and NSDictionary.
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 deepCopy] autorelease];
47 else
48 currObj = [[currObj copy] autorelease];
49 [theArray addObject: currObj];
50 }
51
52 return theArray;
53 }
54
55
56 -(NSMutableArray*) deepMutableContainerCopy
57 {
2d7bd235 »
2010-02-23 Err... adhere to Cocoa's memory management contract, don't screw the …
58 NSMutableArray * theArray = [[NSMutableArray alloc] init];
24dca8df »
2010-02-23 Deep copy categories for NSArray, NSSet, and NSDictionary.
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 deepMutableContainerCopy] autorelease];
66 else
67 currObj = [[currObj copy] autorelease];
68 [theArray addObject: currObj];
69 }
70
71 return theArray;
72 }
73
74
75 -(NSMutableArray*) deepMutableCopy
76 {
2d7bd235 »
2010-02-23 Err... adhere to Cocoa's memory management contract, don't screw the …
77 NSMutableArray * theArray = [[NSMutableArray alloc] init];
24dca8df »
2010-02-23 Deep copy categories for NSArray, NSSet, and NSDictionary.
78 NSEnumerator * enny = [self objectEnumerator];
79 id currObj = nil;
80
81 while(( currObj = [enny nextObject] ))
82 {
83 if( [currObj respondsToSelector: @selector(deepCopy)] )
84 currObj = [[currObj deepMutableCopy] autorelease];
85 else
86 currObj = [[currObj mutableCopy] autorelease];
87 [theArray addObject: currObj];
88 }
89
90 return theArray;
91 }
92
93 @end
Something went wrong with that request. Please try again.