66

I'm working on an app in xcode 4 and everything was going great, then something odd just started happening. Every time I make a new class (any type of class, ViewController, NSObject, etc.) and import it in another .m file I get the error "className.h" file not found.

The files are in the project and the code sense in xcode even supplies the name of the class when I am typing the #import statement.

I quit xcode then cleaned the project and that did nothing.

Any ideas, this is driving me crazy!

Russia Must Remove Putin
  • 374,368
  • 89
  • 403
  • 331
Buyin Brian
  • 2,781
  • 2
  • 28
  • 48

13 Answers13

50

I just had the same problem and tried the above solutions. What worked for me was a clean of the project.

In the menu bar go to...

Product --> Clean

When that is complete hold down the option key and again in the menu bar go to...

Product --> Clean Build Folder

I'm not sure if the clean of the build folder was necessary. It's just become habit for me to do both. I have to do this more than I would like in Xcode.

j0k
  • 22,600
  • 28
  • 79
  • 90
JDCartee
  • 696
  • 6
  • 9
  • 2
    I don't find any option such as Product --> Clean Build Folder. Can you help? – Pawan Sharma Nov 13 '13 at 11:58
  • 3
    You have to hold down the option key while looking at the Product menu to see "Clean Build Folder". – JDCartee Nov 14 '13 at 13:54
  • 37
    You know what's awesome? An IDE that requires you to hold down special keys to see the things you need. That's some good UI design right there. /s – mmr Jan 14 '14 at 00:31
  • 2
    The keybinding for `Clean build folder` is Shift-Command-Option-K – jungledev Jun 23 '17 at 14:40
  • This very annoying problem is still alive on Xcode 11. This suggestion worked - in 1 project. In the 2nd project, I'd deleted the .h because just adding it back had worked in the past. Now, when I go to 'Add file...' and do a search the .h does not appear (the .m does). – user3741598 Jan 24 '20 at 22:14
46

I encounter the same problem and the following steps fix my issues:

  1. Go to the target of project.
  2. Go the the "Build Phases"
  3. Expand the "Compile Sources"
  4. delete the [filename that cause the error].m
  5. Add the file back.
  6. Scroll down, in Build Phases, to "Headers (n items)" and add the .h file in the "Public/Private" section
Community
  • 1
  • 1
Ken W
  • 999
  • 7
  • 10
  • 6
    Based on this solution, I've found that simply using Product > Clean also works. – Dave Taubler Oct 03 '14 at 17:15
  • 1
    Also make sure that in the Build Phases tab, the h file is in Public instead of Project or vise versa depending on your needs. – Nick Dec 04 '15 at 00:53
  • Didn't work for me. Adding IG.framework from infragistics, and then importing their header using angle brackets.... no luck. – Logicsaurus Rex Sep 21 '17 at 19:17
  • very annoying problem, been around for a long time... The above workaround worked for me (Xcode 11.3.1) – W S Feb 20 '20 at 16:09
19

this kind of problem occurs due to cyclic import. Say if you have a header file A.h and you are importing B.h and in B.h if you are again importing A.h then this will show the error A.h file not found...

Gyanendra Singh
  • 1,483
  • 12
  • 15
11

For me, it turned out to be the setting for relative path. When I changed location setting from "Relative to Group" to "Relative to Project", suddenly the header file was found. I noticed in the log that the path where it was looking was incorrect, it didn't seem to traverse the directory tree correctly, which lead me to try the other relative settings.

enter image description here

Chuck Krutsinger
  • 2,830
  • 4
  • 28
  • 50
6

My issue was I added the MetalPetal pod and I couldn't access the "MTIShaderLib.h" header to build custom filters even though the header was declared as public. I tried everything above and more and more and more from other answers but the problem was listed in the directions for the pod installation that I overlooked.

enter image description here

What I had to do was go to my main applications icon (the blue icon), select Build Settings, then in the search box I typed in header search paths.

Under Metal Compiler - Build Options I went to Header Search Paths and pressed the arrow.

I clicked Debug and in the pop up box I pressed the + sign at the bottom and entered:

${PODS_CONFIGURATION_BUILD_DIR}/MetalPetal/MetalPetal.framework/Headers

I then did the same exact thing for Release. Make sure you do the steps for both Debug and Release

enter image description here

enter image description here

Problem was resolved after many frustrating hours.

Lance Samaria
  • 17,576
  • 18
  • 108
  • 256
5

Must be an issue with the software... after quitting xcode and the simulator a few times, it works again. I didn't change a thing. But now autocompletion stopped working! Que sera sera.

Buyin Brian
  • 2,781
  • 2
  • 28
  • 48
4

Open the .m file related to the .h file that gives the error. In the Utilities (on the right bar) go to the target membership and uncheck and check again (or just check if it was unchecked) the target you want.

Adriana
  • 806
  • 11
  • 36
3

maybe you're using #import "something.h" instead of #import ('<>' used for framework files)

Edoz
  • 1,068
  • 1
  • 11
  • 16
2

In file inspector I found that my new .h file path was not in Pod/Classes/

mrgloom
  • 20,061
  • 36
  • 171
  • 301
0

Make sure the user header path was set right!

Jadian
  • 4,144
  • 2
  • 13
  • 10
0

In Build Settings... changing C++ Standard library from libstd++ (GNU C++) to libc++ (LLVM) worked for me!!

Nupur Sharma
  • 1,106
  • 13
  • 15
0

I have solved issue when discover that when i start type import "FileName" there is autocompletion for some header files, but not for all. I guess that file that are not able to fill with auto complete are broken somehow.

Then i just delete them from XCode files tab and drag add again using "Add File" command.

Evgeniy Kleban
  • 6,794
  • 13
  • 54
  • 107
-3

When choosing the template for your new file, choose the Cocoa Touch Class, but not Object-C File, you will get both .m and .h files

goddyang
  • 57
  • 1
  • 3