Jason
Jason

Reputation: 17956

Why won't my objective c implementation file recognize my import statement

Here is my header file

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <PolygonShape.h>

@interface Controller : NSObject {
    IBOutlet UIButton *decreaseButton;
    IBOutlet UIButton *increaseButton;
    IBOutlet UILabel *numberOfSidesLabel;
    //IBOutlet PolygonShape *shape;
}
- (IBAction)decrease;
- (IBAction)increase;
@end

Here is my implementation file

#import "Controller.h"

@implementation Controller
- (IBAction)decrease {
    //shape.numberOfSides -= 1;
}

- (IBAction)increase {
    //shape.numberOfSides += 1;
}
@end

Why am I getting the following error on my #import "Controller.h" line?

error: PolygonShape.h: No such file or directory

The PolygonShape.h and .m files are in the same project and in the same directory as the Controller class.

Upvotes: 2

Views: 2220

Answers (3)

Jacob KB
Jacob KB

Reputation: 31

If you import class A in B and then import class B in A you will get this error

Upvotes: 0

Terry Wilcox
Terry Wilcox

Reputation: 9040

System header files use <>. Your header files should use "".

So it should be:

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "PolygonShape.h"

And you might want to use @class PolygonShape in your header file and do the import in your implementation.

Upvotes: 1

Chuck
Chuck

Reputation: 237010

The angle braces (<>) mean that the file is in a standard include path, such as /usr/include or /System/Library/Frameworks. To import a file relative to the current directory, you need to use double-quotes like you do in #import "Controller.h".

Upvotes: 6

Related Questions