Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode cannot find ProductModuleName-Swift.h

I'm attempting to import my "-Swift.h" file into one of my Objective-C .h files but xcode keeps telling me that the file doesn't exist

#import "Aesculus-Swift.h"

If I command click on the file name it will take me to the generated header file so I know it exists. Why is xcode not able to find it?

enter image description here

enter image description here

like image 875
Kyle Decot Avatar asked Jul 31 '15 13:07

Kyle Decot


2 Answers

This seems like just another issue with Xcode and it's complex tool chain of static analysers and compilers.

Openradar lists radar://21362856 - Swift to Objective-C bridging is unreliable. I am sure there are more but I stopped looking after finding one for this example.

The author imarcelv notes in the description:

I asked a Swift engineer at WWDC in a lab and even he didn't know how to fix this issue.

Steps to Reproduce:

  1. Add a ramdom Swift class to an Objective-C project
  2. Add the #import "ModuleName-Swift.h" file that Xcode generates automatically
  3. Try to use it or just try to compile the project
  4. From time to time it simply doesn't work

It's probably best to file a radar on this issue as it seems that others are already calling it out.

One other thing you could try...

Historically, it was possible for Xcode to completely lose it's syntax highlighting and you could always find out what files the static analyser was giving up on by increasing log level of clang.

I'm not sure if it's still relevant but if I was in your position I'd be trying this command:

defaults write com.apple.dt.Xcode IDEIndexingClangInvocationLogLevel 3

This generates logs you can search with using Console.app for just xcode to highlight the messages. You'll want to trash the derived data of your project to force it to re-compile things.

Although not the same issue as what you're seeing, I have had this post on the syntax highlighting issue bookmarked for years for the above defaults write command to try in times like these.

like image 139
Jessedc Avatar answered Oct 02 '22 14:10

Jessedc


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

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

This tells the compiler to search for headers in the build output directory, which is where Xcode puts the generated header (at least in the case of this framework).

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

Xcode's header and dependency management is a hot mess, and it's not surprising that it doesn't work for you.

like image 44
Ewan Mellor Avatar answered Oct 02 '22 13:10

Ewan Mellor