I'm trying to create a subclass object, whose size can be determined when I declare it. For example, do something near to "circle (int width, int height)", and in the C4WorkSpace, attribute two numbers that define the size of the circle. If I understood correctly, you can use initializers for that, like this one:
- (id) initWithNumber: (int) n {
self = [super init]; ❶ ❷
if (self) {
self->_number = n; ❸
}
return self; ❹
}
...but I didn't quite understand how to use it and where to put it.
Here is the code I'm working with. I inserted "size" into the parameters of the ellipse, just to illustrate what I'm trying to do. My circle.h file:
#import "C4Shape.h"
@interface circle : C4Shape
@end
And the circle.m one:
#import "circle.h"
@implementation circle
-(void) setup
{
[self addGesture:PAN name:@"pan" action:@"move:"];
[self addGesture:TAP name:@"tap" action:@"changeColour"];
[self ellipse:CGRectMake(0, 0, size, size)];
[self setFillColor:[UIColor blackColor]];
[self setStrokeColor:[UIColor blackColor]];
}
-(void) changeColour
{
self.fillColor = [UIColor colorWithRed:[C4Math randomInt: 100]/100.0f green:[C4Math randomInt: 100]/100.0f blue:[C4Math randomInt: 100]/100.0f alpha:1.0f];
}
@end
How is the best way to attribute a variable to a subclass in C4, in this case? If possible, could you explain how I create the object in the C4WorkSpace.m too?
Thanks for your attention. And sorry if I was not clear.