Does the error checking that I have used in main make since?
main.m
#import "Fraction.h"
#import "Complex.h"
#import "XYPoint.h"
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
id dataValue1, dataValue2, result;
Fraction *f1 = [[Fraction alloc] init];
Fraction *f2 = [[Fraction alloc] init];
Complex *c1 = [[Complex alloc] init];
Complex *c2 = [[Complex alloc] init];
// set values
[f1 setTo:2 over:5];
[f2 setTo:1 over:2];
[c1 setReal:10.0 setImaginary:2.5];
[c2 setReal:5.0 setImaginary:1.5];
// dataValue set to fraction
dataValue1 = f1;
dataValue2 = f2;
if ( [dataValue1 class] == [dataValue2 class] )
{
if ( [dataValue1 respondsToSelector: @selector(addVal:)] == YES )
{
@try
{
result = [dataValue1 performSelector: @selector(addVal:) withObject:dataValue2];
if ( [result respondsToSelector: @selector(print)] == YES )
[result performSelector: @selector(print)];
else
NSLog(@"Object doe not respond to a print method.");
}
@catch (NSException *exception)
{
NSLog(@"That didn't go so well... :(");
}
}
else
NSLog(@"The Object doesn't respond the addVal: selector.");
}
else
NSLog(@"Input objects are not the same type!: %@ vs %@.",[dataValue1 class],[dataValue2 class]);
[result release];
// dataValue set to Complex
dataValue1 = c1;
dataValue2 = c2;
if ( [dataValue1 class] == [dataValue2 class] )
{
if ( [dataValue1 respondsToSelector: @selector(addVal:)] == YES )
{
@try
{
result = [dataValue1 performSelector: @selector(addVal:) withObject:dataValue2];
if ( [result respondsToSelector: @selector(print)] == YES )
[result performSelector: @selector(print)];
else
NSLog(@"Object doe not respond to a print method.");
}
@catch (NSException *exception)
{
NSLog(@"That didn't go so well... :(");
}
}
else
NSLog(@"The Object doesn't respond the addVal: selector.");
}
else
NSLog(@"Input objects are not the same type!: %@ vs %@.",[dataValue1 class],[dataValue2 class]);
[result release];
[c1 release];
[c2 release];
[f1 release];
[f2 release];
[pool drain];
return 0;
}