forked from mshafae/CS411SampleCode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforeach.m
50 lines (45 loc) · 1.51 KB
/
foreach.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
// $Id: foreach.m 3142 2011-09-19 09:42:50Z mshafae $
#import <Foundation/Foundation.h>
#import <assert.h>
int main( void ){
NSAutoreleasePool *pool = [NSAutoreleasePool new];
NSDictionary *dict;
NSArray *a;
NSEnumerator *enumerator;
id obj;
dict = [NSDictionary dictionaryWithContentsOfFile: @"demo.plist" ];
assert( dict != nil );
a = [dict allValues];
enumerator = [a objectEnumerator];
while( (obj = [enumerator nextObject]) != nil ){
NSLog( @"Next Object is: %@", obj );
if( [obj isKindOfClass:[NSNumber class]] ){
NSLog( @"it is a number! %g", [(NSNumber*)obj doubleValue] );
}else if( [obj isKindOfClass:[NSString class]] ){
NSLog( @"its is a string! %@", (NSString*)obj );
}else{
if( [obj respondsToSelector: @selector(description)] ){
NSLog( @"its not a number or a string %@", [obj description] );
}else{
NSLog( @"its not a number or a string" );
}
}
}
for( id key in dict ){
obj = [dict objectForKey: key];
NSLog( @"Next Object is: %@", obj );
if( [obj isKindOfClass:[NSNumber class]] ){
NSLog( @"it is a number! %g", [(NSNumber*)obj doubleValue] );
}else if( [obj isKindOfClass:[NSString class]] ){
NSLog( @"its is a string! %@", (NSString*)obj );
}else{
if( [obj respondsToSelector: @selector(description)] ){
NSLog( @"its not a number or a string %@", [obj description] );
}else{
NSLog( @"its not a number or a string" );
}
}
}
[pool release];
return( 0 );
}