Search code examples
objective-ccocoaxcode4compiler-errorsinclude-path

Importing Custom Class .h file into AppDelegate.h with relative route doesn't work


In my Cocoa Application I have created a Custom View Class (subclass of NSView), named "DragAndDropView". Its .h and .m files are placed in the same folder than the AppDelegate.h.

Into the AppDelegate.h, I need to declare an outlet of my DragAndDropView. It looks like this:

#import <Cocoa/Cocoa.h>
#import <DragAndDropView.h>

@interface AppDelegate : NSObject <NSApplicationDelegate> {
@private
    NSWindow        *window;

    DragAndDropView *dragAndDropView;

    // Files
    NSFileManager   *fileMgr;
}

// Outlets
@property (assign) IBOutlet NSWindow *window;
@property (assign) IBOutlet DragAndDropView *dragAndDropView;

@end

With the import of my class (#import ), I become the following error:

'DragAndDropView.h' file not found

Anyone knows how can I fix it?


Solution

  • You need to use quotes instead of angled brackets in your import line. i.e. this:

    #import "DragAndDropView.h"
    

    instead of this:

    #import <DragAndDropView.h>
    

    In essence, the former is for importing headers from your project, the latter is for importing headers from system libraries.