-1

This is 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

This is 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

when i compile the file, i meet this error:

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)
1
  • you are right, could you tell me why? i have removed the function colorName in other file.
    – BlackMamba
    Sep 2, 2013 at 13:28

1 Answer 1

1
-(NSString*) colorName: (ShapeColor)color;

is an Objective-C method and not a function, so you have to use the correct syntax for calling methods. Replace

colorName(mColor)

by

[self colorName:mColor]
2
  • yeah, thank you. the funtion colorName is a private method of class Circle, so i think that i can call colorName like this colorName(mColor)
    – BlackMamba
    Sep 2, 2013 at 13:34
  • 1
    @BlackMamba There is only one syntax for calling methods in Objective-C and Objective-C does not have private methods... you should revisit an Objective-C tutorial.
    – bbum
    Sep 2, 2013 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.