You'll recall that setTo:Over: was a method we developed that allowed you to set a fraction's numerator and denominator in a single method call. There is no way to synthesize a method for more than one property (that is, a method that takes multiple arguments).
Cheers,
Steve Kochan
Thanks for your answer.
If I don't want to set a fraction's numerator and denominator in a single method call, can
setTo: over: be deleted from the program like this?
Fraction.h
#import <Foundation/Foundation.h>
@interface Fraction : NSObject {
int numerator;
int denominator;
}
@property int numerator, denominator;
-(void) print;
//-(void) setTo: (int) n over: (int) d;
-(double) convertToNum;
@end
Fraction.m
#import "Fraction.h"
@implementation Fraction
@synthesize numerator, denominator;
-(void) print
{
NSLog(@"%i/%i", numerator, denominator);
}
-(double) convertToNum
{
if (denominator != 0)
return (double) numerator / denominator;
else
return 1.0;
}
@end
FractionTest.m
#import "Fraction.h"
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Fraction *myFraction = [[Fraction alloc] init];
//set fraction to 1/3
[myFraction setNumerator: 1];
[myFraction setDenominator: 3];
//display the fraction
NSLog(@"The value of myFraction is:");
[myFraction print];
[myFraction release];
[pool drain];
return 0;
}
And sorry for my bad English. I can't understand "There is no way to synthesize a method for more than one property (that is, a method that takes multiple arguments).". In this example, we can set 2 instance variables using 1 method. Why we can't synthesize a method for more than property?