Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Xcode not find the headers in a folder reference?

For example I drag in a folder "SharedClasses" with shared source code files as a folder reference into Xcode. The folder reference appears in the Project Navigator and lists all .h and .m files correctly.

But Xcode refuses to import them. I tried all kinds of import:

#import "Utility.h"

#import "SharedClasses/Utility.h"

#import <SharedClasses/Utility.h>

None of them work. But a folder reference exists and it contains "Utilities.h"

Xcode knows where the folder comes from so what must I do that it looks inside it?

like image 412
openfrog Avatar asked Oct 06 '13 19:10

openfrog


People also ask

How do I open a header file in Xcode?

Holding the Command key, click the import/include statement to view the header. Also, you can Command-click on a symbol to jump to the header file that defines it.

How do I add a header search path in Xcode 13?

Look at Preferences->Locations->"Custom Paths" in Xcode's preference. A path added here will be a variable which you can add to "Header Search Paths" in project build settings as "$cppheaders", if you saved the custom path with that name. Set HEADER_SEARCH_PATHS parameter in build settings on project info.

Where does CPP look for header files?

For C++ programs, it will also look in /usr/include/g++-v3, first.


1 Answers

Because the files are in a different folder than the project Xcode will not include it in the header search path. To fix this add an entry for User Header Search Paths (select your project, select Build Settings, filter to "user header search paths", add the value) in the project that points to the original folder reference. For example in a project I'm working on I have code that is shared between several projects in a workspace which is stored at the same folder level as the projects in a folder named shared. My User Header Search Paths has the following:

$(PROJECT_DIR)/../Shared/MySharedCode/

like image 175
RyanR Avatar answered Oct 02 '22 14:10

RyanR