View Full Version : cant figure out what's wrong

Sep 1, 2010, 01:13 AM
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.

#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;


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;

Sep 1, 2010, 01:46 AM
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.

Sep 1, 2010, 01:52 AM
Also you misspelled setThird.

Sep 1, 2010, 04:50 PM
Besides your miss spelling error 'setThird' you forgot to add the '@end' after your interface section.


Sep 1, 2010, 05:12 PM
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.

Sep 1, 2010, 08:09 PM
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?

Sep 1, 2010, 08:49 PM
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.

Sep 2, 2010, 02:32 AM
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.