- Joined
- Apr 21, 2009
- Messages
- 1
- Reaction score
- 0
- Points
- 1
- Location
- Lexington, MA
- Your Mac's Specs
- Macbook Pro 17 w/250GB SSD drive, 4GB running VMWare Fusion; iPhone 3G
Taking the Stanford U iPhone developer class & starting work on the lessons. Below is a simple introspection function to examine various classes. Question is: Why does uncommenting the one line with the NSArray cause the function to recurse/repeat numerous times through all the objects, while leaving it commented out makes it run as expected (one pass through the list of objects)? In fact, there are several other functions I call from main(), and their objects will show up in the output as well if I uncomment the NSArray line! I assume this is a pointer/bounds problem, but I don't know enough yet to figure out where the problem is in my syntax.
Also, a little amazed so much code is required to set up an array initialized with integers - any faster way?
Thanks for your help!
Also, a little amazed so much code is required to set up an array initialized with integers - any faster way?
Thanks for your help!
Code:
void PrintIntrospectionInfo() {
NSLog(@" ");
NSLog(@"*** PrintIntrospectionInfo ***");
SEL mysel = @selector(lowercaseString);
NSMutableArray *myObjs = [NSMutableArray arrayWithObjects:
[NSMutableString stringWithFormat:@"this is test# %d", 12],
@"foo",
[NSArray arrayWithObjects:@"hello", @"there", nil],
[NSURL URLWithString:@"http://www.abc.com/headlines"],
[NSProcessInfo processInfo],
// [NSArray arrayWithObjects:[NSNumber numberWithInt:5], [NSNumber numberWithInt:4], [NSNumber numberWithInt:3], nil],
[NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSURL URLWithString:@"http://www.stanford.edu"], @"Stanford University",
[NSURL URLWithString:@"http://www.apple.com"], @"Apple",
[NSURL URLWithString:@"http://cs193p.stanford.edu"], @"CS193P",
nil]
];
for (id key in myObjs) {
NSLog(@"Class Name: %@", [key className]);
if ([key isKindOfClass:[NSArray class]]) {
NSLog(@"Array size is: %d", [key count]);
} else {
NSLog(@"Object value: '%@'", key);
}
NSLog(@"Is member of NSString: %s", ([key isMemberOfClass:[NSString class]] ? "YES" : "NO"));
NSLog(@"Is kind of NSString: %s", ([key isKindOfClass:[NSString class]] ? "YES" : "NO"));
NSLog(@"Responds to lowercaseString: %s", ([key respondsToSelector:mysel] ? "YES" : "NO"));
if ([key respondsToSelector:mysel])
NSLog(@"lowercaseString is: '%@'", [key performSelector:mysel]);
NSLog(@"===============================================");
}
} //PrintIntrospectionInfo