I'm getting the following warning when I try to compile:
Here's the code that seems relevant...
from PolygonShape.h:
from PolygonShape.m:
and from the main file
I don't know that I'm understanding how to properly use init and alloc...
Edit: The log ends up showing this:
Which seems to match up with what the warning says during compile.
'PolygonShape' may not respond to '+initWithNumberOfSides:minimumNumberOfSides:maximumNumberOfSides:'
Here's the code that seems relevant...
from PolygonShape.h:
Code:
@interface PolygonShape : NSObject
Code:
-(id)initWithNumberOfSides:(int)sides minimumNumberOfSides:(int)min maximumNumberOfSides:(int)max;
from PolygonShape.m:
Code:
-(id)initWithNumberOfSides:(int)sides minimumNumberOfSides:(int)min maximumNumberOfSides:(int)max
{
if (self = [super init])
{
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"Triangle", 3,
@"Square", 4,
@"Pentagon", 5,
@"Hexagon", 6,
@"Heptagon", 7,
@"Octagon", 8,
@"Nonagon", 9,
@"Decagon", 10,
@"Hendecagon", 11,
@"Dodecagon", 12,
nil];
numberOfSides = sides;
minimumNumberOfSides = min;
maximumNumberOfSides = max;
angleInDegrees = (180 * (numberOfSides - 2)/numberOfSides);
angleInRadians = (angleInDegrees * M_PI / 180);
name = [dictionary objectForKey: [NSString stringWithFormat:@"%d", sides]];
}
return self;
}
-(id)init
{
if (self = [super init])
{
return [self initWithNumberOfSides:5 minimumNumberOfSides:3 maximumNumberOfSides:10];
}
}
-(NSString *)description
{
return [NSString stringWithFormat:@"Hello, I am a %d-sided polygon (aka, a '%@',) with angles of %f degrees (%f radians.)", numberOfSides, name, angleInDegrees, angleInRadians];
}
and from the main file
Code:
#import "PolygonShape.h"
Code:
PolygonShape *test = [PolygonShape initWithNumberOfSides:5 minimumNumberOfSides:3 maximumNumberOfSides:10];
NSLog (@"%@", [test description]);
I don't know that I'm understanding how to properly use init and alloc...
Edit: The log ends up showing this:
2009-10-08 23:30:27.879 Assignment 1B - WhatATool[10579:a0f] +[PolygonShape initWithNumberOfSides:minimumNumberOfSides:maximumNumberOfSides:]: unrecognized selector sent to class 0x100003750
2009-10-08 23:30:27.880 Assignment 1B - WhatATool[10579:a0f] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[PolygonShape initWithNumberOfSides:minimumNumberOfSides:maximumNumberOfSides:]: unrecognized selector sent to class 0x100003750'
Which seems to match up with what the warning says during compile.