-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscovery.m
144 lines (97 loc) · 3.12 KB
/
discovery.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//
// discovery.m
// shizzeeps
//
// Created by Sue Brown on 11/15/09.
// Copyright 2009 House of Crunchy. All rights reserved.
//
#import "discovery.h"
@implementation discovery
@synthesize theArray;
@synthesize theDict;
/* discover
decide whether to discover the dict, the array, or both
-------------------------------------------------------------------------- */
- (void) discover {
br = @"==========================================================\n\n";
if (self.theDict)
[self discoverDictionary];
if (self.theArray)
[self discoverArray];
}
#pragma mark -
#pragma mark Dictionary Methods
/* discover Dict
print out info about the dict
-------------------------------------------------------------------------- */
- (void) discoverDictionary {
NSLog(@"%@", br);
// count
NSLog(@"Dictionary count: %i%@", [self.theDict count], br);
NSLog(@"%@", br);
// all keys
NSLog(@"All the dictionary's keys: %@", [[self.theDict allKeys] description]);
NSLog(@"%@", br);
// enumerate
NSLog(@"ENUMERATING THE WHOLE DICTIONARY\n");
[self enumerateDictionary: self.theDict];
}
/* enumerate Dictionary
recursively enumerates a dictionary
-------------------------------------------------------------------------- */
- (void) enumerateDictionary: (NSDictionary *) d {
NSEnumerator *enumerator = [d objectEnumerator];
id anObject;
int i = 0;
while (anObject = [enumerator nextObject]) {
if ([anObject isKindOfClass:[NSArray class]]) {
NSLog(@"ITEM #%i IS AN ARRAY: %@", i, [anObject description]);
[self enumerateArray:anObject];
}else if ([anObject isKindOfClass:[NSDictionary class]]) {
NSLog(@"ITEM %i IS A DICTIONARY: ", i);
// all keys
NSLog(@"All the dictionary's keys: %@", [[anObject allKeys] description]);
NSLog(@"%@", br);
[self enumerateDictionary:anObject];
} else {
NSLog(@"ITEM #%i IS A %@: %@", i, [[anObject class] description], [anObject description]);
i++;
}
}
[enumerator release];
}
#pragma mark -
#pragma mark Array Methods
/* discover Array
print out info about the array and/or the dict
-------------------------------------------------------------------------- */
- (void) discoverArray {
NSLog(@"%@", br);
// count
NSLog(@"Array count: %i%@", [self.theArray count], br);
// enumerate
NSLog(@"ENUMERATING THE WHOLE ARRAY\n");
[self enumerateArray: self.theArray];
}
/* enumerate Array
recursively enumerates an array
-------------------------------------------------------------------------- */
- (void) enumerateArray: (NSArray *) a {
NSEnumerator *enumerator = [a objectEnumerator];
id anObject;
int i = 0;
while (anObject = [enumerator nextObject]) {
if ([anObject isKindOfClass:[NSArray class]]) {
NSLog(@"ITEM #%i IS AN ARRAY of %i items: ", i, [anObject count]);
[self enumerateArray:anObject];
}else if ([anObject isKindOfClass:[NSDictionary class]]) {
NSLog(@"ITEM %i IS A DICTIONARY of %i items: ", i, [anObject count]);
[self enumerateDictionary:anObject];
} else {
NSLog(@"ITEM #%i IS A %@: %@", i, [[anObject class] description], [anObject description]);
i++;
}
}
[enumerator release];
}
@end