Sometimes in programming the little things are the ones that throw me off. The big concepts I always get as they are usually explained very well. I have the following code and I just don't understand why I need the *colorname before the function name. Does it have to do with the function call within NSLog?
This is not the whole code, just an excerpts:
This is not the whole code, just an excerpts:
Code:
typedef enum {
kRedColor,
kGreenColor,
kBlueColor
} ShapeColor;
NSString *colorName (ShapeColor color)
{
switch (color) {
case kRedColor:
return (@"red");
break;
case kGreenColor:
return @"green";
break;
case kBlueColor:
return @"blue";
break;
}
return @"no clue";
} // colorName
@implementation Rectangle
- (void) setFillColor: (ShapeColor) c
{
fillColor = c;
} // setFillColor
- (void) setBounds: (ShapeRect) b
{
bounds = b;
} // setBounds
- (void) draw
{
NSLog (@"drawing a rectangle at (%d %d %d %d) in %@",
bounds.x, bounds.y,
bounds.width, bounds.height,
colorName(fillColor));
} // draw
@end // Rectangle