I've just started learning objective-c, from a book. I'm using Xcode to write it in. I've written in a piece of code that it told me to, but when I run it it displays this error message:
This is the code I have:
The only thing I could think of that may be the problem is the book was teaching objective-c 1.0, instead of 2.0, which I presume is what Xcode is using.
Could you please help?
[Session started at 2010-05-05 20:58:37 +0100.]
GNU gdb 6.3.50-20050815 (Apple version gdb-1461.2) (Fri Mar 5 04:43:10 UTC 2010)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys001
Loading program into debugger
Program loaded.
run
[Switching to process 31009]
Running
2010-05-05 20:58:38.172 prog2[31009:a0f] *** NSInvocation: warning: object 0x100002080 of class 'Fraction' does not implement methodSignatureForSelector: -- trouble ahead
2010-05-05 20:58:38.175 prog2[31009:a0f] *** NSInvocation: warning: object 0x100002080 of class 'Fraction' does not implement doesNotRecognizeSelector: -- abort
sharedlibrary apply-load-rules all
(gdb)
This is the code I have:
Code:
// Program to work with fractions class version
#import <stdio.h>
#import <objc/Object.h>
//------- @interface section -------
@interface Fraction: Object
{
int numerator;
int denominator;
}
-(void) print;
-(void) setNumerator: (int) n;
-(void) setDenominator: (int) d;
@end
//------- @implementation section -------
@implementation Fraction;
-(void) print
{
printf (" %i/%i ", numerator, denominator);
}
-(void) setNumerator: (int) n
{
numerator = n;
}
-(void) setDenominator: (int) d
{
denominator = d;
}
@end
//------- program section -------
int main (int argc, char *argv[])
{
Fraction *myFraction;
// Create an instance of a Fraction
myFraction = [Fraction alloc];
myFraction = [myFraction init];
// Set fraction to 1/3
[myFraction setNumerator: 1];
[myFraction setDenominator: 3];
// Display the fraction using the print method
printf ("The value of myFraction is:");
[myFraction print];
printf ("\n");
[myFraction free];
return 0;
}
The only thing I could think of that may be the problem is the book was teaching objective-c 1.0, instead of 2.0, which I presume is what Xcode is using.
Could you please help?