Results 1 to 2 of 2
  1. #1

    Member Since
    Apr 22, 2009
    Lexington, MA
    Macbook Pro 17 w/250GB SSD drive, 4GB running VMWare Fusion; iPhone 3G
    Question New to Objective C - what is the problem with this?
    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

  2. #2

    Aptmunich's Avatar
    Member Since
    Mar 09, 2004
    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)...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Need help in objective C
    By prateek.chaubey in forum iOS Development
    Replies: 3
    Last Post: 09-23-2011, 10:12 PM
  2. Objective-C
    By eddielee in forum OS X - Development and Darwin
    Replies: 2
    Last Post: 02-02-2011, 01:27 PM
  3. new to objective c - help with tiny problem
    By natronp in forum OS X - Development and Darwin
    Replies: 1
    Last Post: 06-09-2010, 02:18 PM
  4. Is Objective For me?
    By Estanislao in forum OS X - Apps and Games
    Replies: 1
    Last Post: 05-26-2009, 05:13 AM
  5. Objective-C
    By AstralZenith in forum OS X - Development and Darwin
    Replies: 13
    Last Post: 03-09-2003, 11:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts