这是Circle.h
:
#import <Foundation/Foundation.h>
typedef enum{
KCircle,
KRectangle
}ShapeType;
typedef enum{
KRedColor,
KGreenColor,
KBlueColor
}ShapeColor;
typedef struct{
int x, y, width, height;
}ShapeRect;
typedef struct{
ShapeType type;
ShapeColor fillColor;
ShapeRect bounds;
}Shape;
@interface Circle : NSObject{
ShapeColor mColor;
ShapeRect mBound;
}
-(void) setBound: (ShapeRect) bound;
-(void) setFillColor: (ShapeColor) color;
-(void) draw;
@end
这是Circle.m
#import "Circle.h"
@implementation Circle
-(void) setBound:(ShapeRect)bound{
mBound = bound;
}
-(void)setFillColor:(ShapeColor)color{
mColor = color;
}
-(NSString*) colorName: (ShapeColor)color{
switch (color) {
case KGreenColor:
return @"Green";
break;
case KRedColor:
return @"Red";
break;
case KBlueColor:
return @"Blue";
break;
default:
break;
}
}
-(void) draw
{
NSLog(@"drawing a circle (%d %d %d %d) in %@",
mBound.x, mBound.y, mBound.width, mBound.height, colorName(mColor));
}
@end
当我编译文件时,我遇到了这个错误:
Undefined symbols for architecture x86_64:
"_colorName", referenced from:
-[Circle draw] in Circle.o
(maybe you meant: _colorName1)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)