I’am doing some exercises, but can’t understand what is wrong.
I have:
Fraction+MathOps.h
#import "Fraction.h"
@interface Fraction (MathOps)
-(Fraction *) add:(Fraction *) f;
@end
Here is Fraction+MathOps.m
#import "Fraction+MathOps.h"
@implementation Fraction (MathOps)
-(Fraction *) add:(Fraction *) f
{
//To add two fraction
// a / b + c / d = ((a * b) + (b * c)) / (b * d)
Fraction *result = [[Fraction alloc] init];
result.numerator = (self.numerator * f.denominator) + (self.denominator * f.numerator);
result.denominator = self.denominator * f.numerator;
[result reduce];
return result;
}
@end
and will try to call method add from categories in main.m
Fraction *ca = [[Fraction alloc] init];
Fraction *cb = [[Fraction alloc] init];
Fraction *cresult;
[ca setTo: 1 over: 3];
[cb setTo: 2 over: 5];
cresult = [ca add: cb];
and have compiler error (No visible @interface for ‘Fraction’ declares the selector ‘add:’
) at cresult = [ca add: cb] string.
Problem solved:
I didn’t include Fraction+MathOps.h in main.m
Thanks Richard and Carl Norum