| OS X - Development and Darwin Discussion and questions about development for Mac OS X. |
| Post Reply | New Thread | Subscribe |
|
|
Thread Tools |
![]() Member Since: Apr 21, 2009
Location: Lexington, MA
Posts: 1
![]() Mac 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! 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
|
| QUOTE Thanks | |
![]() Member Since: Mar 09, 2004
Location: Munich
Posts: 9,075
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Mac Specs: Aluminium Macbook 2.4 Ghz 4GB RAM, SSD 24" Samsung Display, iPhone 4, iPad 2
|
Hey! I've been looking at the Stanford classes as well... they're pretty good!
Perhaps you'd want to try using an arrayEnumurator to iterate over the objects instead? Not sure though, I can't remember how I did it exactly (don't have my code here)... |
| QUOTE Thanks | |
| Post Reply | New Thread | Subscribe |
| Thread Tools | |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
|
|||||||
Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| diagnosing kernel task/CPU problem on Macbook Air | nick_harambee | Apple Notebooks | 9 | 08-20-2011 07:20 AM |
| Problem With Keyboard...... | mmcltd | OS X - Operating System | 4 | 02-02-2010 06:47 PM |
| Possible faulty CPU thermometer, common problem? | dyaballikl | Apple Notebooks | 6 | 11-16-2008 12:21 AM |
| Microsoft Messenger Problem | millenium_spike | OS X - Apps and Games | 4 | 09-16-2008 01:11 AM |
| Problem Darwin Server + VLC | nanaki | Web Design and Hosting | 0 | 03-13-2008 07:27 AM |
All times are GMT -4. The time now is 05:46 PM.
Powered by vBulletin