cant figure out what's wrong

Discussion in 'Mac Programming' started by macattack87, Aug 31, 2010.

  1. macrumors member

    Joined:
    Nov 14, 2007
    Location:
    Jersey
    #1
    Hey everyone

    I've been trying to teach myself objective-c for sometime now and I am following a book i bought. When i try to compile this little program it fails, can someone please tell me what is wrong.

    Code:
    
    #import <Foundation/Foundation.h>
    
    
    @interface Mycombo: NSObject
    {
    	int firstnumber;
    	int secondnumber;
    	int thirdnumber;
    	
    }
    
    -(void) print;
    -(void) setfirst: (int) x;
    -(void) setsecond: (int) y;
    -(void) setthird: (int) z;
    
    @implementation Mycombo
    -(void) print
    {
    	NSLog(@"%i - %i - %i", firstnumber, secondnumber, thirdnumber); 
    	
    }
    
    -(void) setFirst: (int) x
    {
    	firstnumber = x;
    }
    
    -(void) setSecond: (int) y
    {
    	secondnumber = y;	
    }
    
    -(void) seThird: (int) z
    {
    	thirdnumber = z;
    }
    
    @end
    
    
    int main (int argc, const char *argv[])
    {
    	NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    	
    	Mycombo * combo = [[Mycombo alloc] init];
    	
    	[combo setFirst: 10];
    	[combo setSecond: 22];
    	[combo setThird: 31];
    	
    	NSLog (@"your new combo is:");
    	[combo print];
    	[combo release];
    	
    	
    	
    	[pool drain];
    	
    	return 0;
    }
    
    
     
  2. macrumors 603

    Joined:
    Aug 9, 2009
    #2
    There are many books. Which book are you using? Title, author, edition. Be specific.

    When you try to compile, there can be many reasons for failure. Post the specific error message you get.

    Also, remember that Objective-C is case-sensitive, so setfirst is different from setFirst.
     
  3. macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #3
    Also you misspelled setThird.
     
  4. macrumors 68000

    Joined:
    Sep 8, 2006
    #4
    Besides your miss spelling error 'setThird' you forgot to add the '@end' after your interface section.

    -Lars
     
  5. macrumors regular

    Joined:
    Apr 7, 2004
    Location:
    Israel
    #5
    setfirst is not the same as setFirst

    setsecond is not the same as setSecond

    setthird is not the same as setThird


    C based languages are case-sensitive.
     
  6. thread starter macrumors member

    Joined:
    Nov 14, 2007
    Location:
    Jersey
    #6
    thanks guys i got it working last nite but now i have another question:

    how does one tie a code like this into something they made in interface builder?

    for example. Lets say I make a button and a text field in interface builder, how do i make it so that when you push the button it displays the combo?
     
  7. macrumors 603

    Joined:
    Aug 9, 2009
    #7
    Get a book that tells you how to do it, step by step in a guided process.

    Any of the books that covers Cocoa programming for Mac OS X would do this. The Hillegass book "Cocoa Programming for Mac OS X" is widely recommended. I think it's at the 3rd edition now; don't bother getting earlier ones.

    If you were already an experienced programmer, then you might be able to learn it just by reading Apple's reference docs and online tutorials. Since you're not, I strongly recommend a book.
     
  8. macrumors 68000

    Joined:
    Sep 8, 2006
    #8
    I agree with Chown33. I am also learning and can't wait till I get to gui stuff. If you jump ahead like that you will get lost. Work through objet C first and walk before you try to run.
     

Share This Page