Objective-C problem

Posted by: FSM

Objective-C problem - 09/26/09 09:07 PM

here is a simple program i am trying to learn Objective-C 2.0. this just has to do with fractions. however, i get an error when i build and run and i haven't figured out how to debug what is wrong. can you spot my error and tell me what it is?

// First program example

#import <Foundation/Foundation.h>

// ---- @interface section ----

@interface Fraction: NSObject

	int numerator;
	int denominator;

-(void) print;
-(void) setNumerator: (int) n;
-(void) setDenominator: (int) d;

// ---- @implmentation section ----

@implementation Fraction
-(void) print
	NSLog (@"%i/%i", numerator, denominator);

-(void) setNumerator: (int) n
	numerator = n;

-(void) setDenominator: (int) d
	denominator = d;


// ---- program section ----

int main (int argc, char *argv[])
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
	Fraction *myFraction;
	// create instance of a Fraction
	myFraction = [Fraction alloc];
	myFraction = [myFraction init];
	// Set fraction to 1/3
	[myFraction setNumerator: 1];
	[myFraction setDenominator: 3];
	// Diplay the fraction using the print method

	NSLog (@"The value of myFraction is:");
	[myFraction print];
	[myFraction release];
    [pool drain];
    return 0;
Posted by: FSM

Re: Objective-C problem - 09/29/09 02:45 AM

switched from my Macbook to my Mac Pro and copy and pasted the code into an email and pasted it into Xcode on the Mac Pro and it ran flawlessly. must have just been my Macbook. i have no clue why it didn't work there, but it's good to know that my eyes not spotting the error wasn't the reason. ;~)