New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

Start a Discussion

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

New to Objective C - what is the problem with this?

Post Reply New Thread Subscribe

Thread Tools

Member Since: Apr 21, 2009
Location: Lexington, MA
Posts: 1
rb1383 is on a distinguished road
Mac Specs: Macbook Pro 17 w/250GB SSD drive, 4GB running VMWare Fusion; iPhone 3G

rb1383 is offline
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!

void PrintIntrospectionInfo() {
	NSLog(@" ");
	NSLog(@"*** PrintIntrospectionInfo ***");
	SEL mysel = @selector(lowercaseString);
	NSMutableArray *myObjs = [NSMutableArray arrayWithObjects:
		[NSMutableString stringWithFormat:@"this is test# %d", 12],
		[NSArray arrayWithObjects:@"hello", @"there", nil],
		[NSURL URLWithString:@""],
		[NSProcessInfo processInfo],
//		[NSArray arrayWithObjects:[NSNumber numberWithInt:5], [NSNumber numberWithInt:4], [NSNumber numberWithInt:3], nil],
		[NSMutableDictionary dictionaryWithObjectsAndKeys:
			[NSURL URLWithString:@""],     @"Stanford University",
			[NSURL URLWithString:@""],        @"Apple",
			[NSURL URLWithString:@""],  @"CS193P",
	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]);
}  //PrintIntrospectionInfo
QUOTE Thanks

Aptmunich's Avatar
Member Since: Mar 09, 2004
Location: Munich
Posts: 9,073
Aptmunich has a brilliant futureAptmunich has a brilliant futureAptmunich has a brilliant futureAptmunich has a brilliant futureAptmunich has a brilliant futureAptmunich has a brilliant futureAptmunich has a brilliant futureAptmunich has a brilliant futureAptmunich has a brilliant futureAptmunich has a brilliant futureAptmunich has a brilliant future
Mac Specs: Aluminium Macbook 2.4 Ghz 4GB RAM, SSD 24" Samsung Display, iPhone 4, iPad 2

Aptmunich is offline
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

« newbie Xcode question | terminal compiling help »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Starter
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 08:11 AM.

Powered by vBulletin
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.

Welcome to

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!

(4 digit year)

Already a member?