1
votes

So I have an Objective-C codebase that I'm trying to add Swift files to. I created my bridging header which mostly works but run into issues when importing certain classes. I have had success using classes from my Project-Bridging-Header.h in my Swift files and had success using my Swift classes by importing Project-Swift.h to my Obj-c classes. However, importing certain classes cause file not found errors. These classes that cause issues are just obj-c classes I've created.

The errors I'm receiving are: 'Project-Swift.h' file not found, and Failed to import bridging header 'path/to/header'.

I have previously seen these headers work and have used swift code in objective c and vice versa successfully. It's just when I import certain objective-c classes to my bridging header that it complains.

Has anyone experienced this or know what might be happening?

2
Where are the classes that aren't found located, and what are the import statements you are using?l'L'l
My Bridging header is located at $(SRCROOT)/Project/Supporting Files/Project-Bridging-Header.h and the swift header is automatically generated, so wherever Xcode puts it I guess. I'm using import statements like `#import "MyClass.h", which works for certain classes but not otherschetem

2 Answers

0
votes

I faced a similar problem and it turned out that I had a cricular reference where my Swift class used my OjbC class which in turn used Swift class.

I resolved it by using froward declaration in ObjC header and importing Project-Swift.h in .m

0
votes

I assume you have checked out this guide, Using Swift with Cocoa and Objective-C (Swift 2.2), otherwise you might want to take a look first to see whether the guidelines are helpful to your situation. You may want to double check particularly for some special case like Referencing a Swift Class or Protocol in an Objective-C Header.

If that doesn't work, double check whether those classes in question are set for the correct target(s). And clean and rebuild your project.