Chris Nolet
Chris Nolet

Reputation: 9083

Swift and Objective C: Project-Swift.h and Project-Bridging-Header.h conflict

I have a project that intermingles Swift and Objective-C.

I'm currently trying to call a method from Swift, on a View Controller written in Objective-C.

To expose that method, I added the View Controller's header to the Bridging-Header.h file.

However, the View Controller references Project-Swift.h, which apparently 'does not exist' when the bridging header is being compiled. If I remove the inclusion of Project-Swift.h, the project compiles, however then I don't have access to the Swift functionality I need from the Objective-C end.

The exact error is:

"/Project/ViewController.h:10:9: error: 'Project-Swift.h' file not found
#import "Project-Swift.h"
        ^
<unknown>:0: error: failed to import bridging header '/Project/Project-Bridging-Header.h'

I seem to have a chicken and egg problem.

Any ideas on how to solve this? Can I call an Objective-C method without including the bridging header?

Upvotes: 1

Views: 1463

Answers (1)

Jernej Strasner
Jernej Strasner

Reputation: 4620

I suggest that you include the Project-Swift.h file inside the .m file, so in ViewController.m. If you have any classes defined in there that you need in the header, just add forward class declarations with @class MyClassFromProjectSwift.

Upvotes: 4

Related Questions