2

I am testing myObjCClass which uses a forward declaration to get a Swift class I'm using, I did this because I was getting "failed to emit precompiled header" if I imported the Bridging Header in the .h file. In forward declaration my bridging header import (-Swift.h) is in the .m file. When I try to test this I am able to test my Swift Class but not the classes that inherit from this. I have tried adding #import "MyProject-Swift.h" in my test but I will get the error file not found.

- Obj-C.h file:

// forward declaration
@class mySwiftClass;

- Obj-C.m file:

//import bridging
#import "MyProject-Swift.h"

- Obj-C-Tests.m file:
 
//import that fails
#import "MyProject-Swift.h"

How can I fix this? I just want to test the Swift classes I am using in my Objective-C code.

I have already tried making a new bridging header and importing the main target one into the new test target bridging header, that will give me another "failed to emit precompiled header" I have also tried to set the test target bridging header to the main targets bridging header.

SRed
  • 185
  • 2
  • 12

1 Answers1

1

The problem is that the -Swift.h bridging header file is generated automatically into the DerivedSources directory, which is not in the header search path of other targets.

Therefore, you need to add it:

  • Open the the test target settings
  • Navigate to Build settings -> Search Paths -> Header Search Paths
  • Add the value $CONFIGURATION_TEMP_DIR/Your-project-name.build/DerivedSources

Header Search Path example

Now the import (and everything) should work: Test outcome

Andreas Oetjen
  • 9,889
  • 1
  • 24
  • 34