Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

macattack87

macrumors member
Original poster
Nov 14, 2007
64
0
Jersey
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;
}
 
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.
 
Besides your miss spelling error 'setThird' you forgot to add the '@end' after your interface section.

-Lars
 
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.
 
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?
 
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.
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.