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.714 kb
24dca8d @uliwitness Deep copy categories for NSArray, NSSet, and NSDictionary.
authored
1 //
2 // NSSet+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 "NSSet+DeepCopy.h"
14
15
16 @implementation NSSet (UKDeepCopy)
17
18 -(NSSet*) deepCopy
19 {
2d7bd23 @uliwitness Err... adhere to Cocoa's memory management contract, don't screw the …
authored
20 NSMutableSet * theSet = [[NSMutableSet alloc] initWithCapacity: [self count]];
24dca8d @uliwitness Deep copy categories for NSArray, NSSet, and NSDictionary.
authored
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 [theSet addObject: currObj];
31 }
32
33 return theSet;
34 }
35
36
37 -(NSMutableSet*) deepMutableContainerCopy
38 {
2d7bd23 @uliwitness Err... adhere to Cocoa's memory management contract, don't screw the …
authored
39 NSMutableSet * theSet = [[NSMutableSet alloc] init];
24dca8d @uliwitness Deep copy categories for NSArray, NSSet, and NSDictionary.
authored
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 [theSet addObject: currObj];
50 }
51
52 return theSet;
53 }
54
55
56 -(NSMutableSet*) deepMutableCopy
57 {
2d7bd23 @uliwitness Err... adhere to Cocoa's memory management contract, don't screw the …
authored
58 NSMutableSet * theSet = [[NSMutableSet alloc] init];
24dca8d @uliwitness Deep copy categories for NSArray, NSSet, and NSDictionary.
authored
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 [theSet addObject: currObj];
69 }
70
71 return theSet;
72 }
73
74 @end
Something went wrong with that request. Please try again.