Xcode cannot find ProductModuleName-Swift.h

I try to import the file "-Swift.h" into one of my Objective-Ch files, but xcode keeps telling me that the file does not exist

#import "Aesculus-Swift.h" 

If I click on the file name, it will lead me to the generated header file so that I know that it exists. Why can't xcode find it?

enter image description here

enter image description here

+5
source share
4 answers

This seems like another issue with Xcode and a complex chain of static analyzer and compiler tools.

Openradar lists the radar: // 21362856 - The Objective-C high-speed connection is unreliable . I am sure there are more, but I stopped looking after one of the examples.

The author imarcelv notes in the description:

I asked a Swift engineer at WWDC in the laboratory, and even he did not know how to fix this problem.

Playback steps:

  • Add ramdom Swift class to Objective-C project
  • Add the #import file "ModuleName-Swift.h", which Xcode automatically generates.
  • Try using it or just try to compile the project
  • It just doesn't work from time to time

It is probably best to record a radar on this issue, as it seems that others are already causing it.

Another thing you could try ...

Historically, Xcode has completely lost syntax highlighting, and you can always find out which files the static analyzer refused by increasing the level of the clang log.

I'm not sure how relevant this is, but if I were in your place, I would try this command:

 defaults write com.apple.dt.Xcode IDEIndexingClangInvocationLogLevel 3 

This creates logs that you can search with Console.app for xcode only to highlight messages. You will want to destroy the received data of your project in order to make it recompile things.

Although this is not the same problem as you, I had this post on the syntax highlighting issue noted for many years for the above defaults write command, try at such times.

+5
source

I solved this recently by adding the following entry to my .xcconfig (you can add it in Xcode Build Settings> User Header Search Paths if you want).

 USER_HEADER_SEARCH_PATHS = $(BUILT_PRODUCTS_DIR)/MyFramework.framework/Headers 

This tells the compiler to look for headers in the assembly's output directory, where Xcode places the generated header (at least in the case of this structure).

In my case, this is a directory like ~/Library/Developer/Xcode/DerivedData/MyProject-LongCode/Build/Products/Debug-iphonesimulator/MyFramework.framework/Headers/MyFramework . You can also find your generated header.

Xcode's header and dependency management is a hot mess, and no wonder it doesn't work for you.

+1
source

I had problems with this stuff and I found that your -Swift file is the name of your target (and not just the name of your target). I found useful data here: http://ericasadun.com/2014/08/21/swift-calling-swift-functions-from-objective-c/

0
source

When you encounter this situation, just find your file "ProductName-Swift.h" only with cmnd + click on it (even if xcode shows a warning that it was not found, #import "Aesculus-Swift.h" line still available for clicks), and then in the window that opens the code editor, select the context menu and the option "Show in Finder", and then explicitly add it to your project.

enter image description here

0
source

All Articles