Mike Nathas Mike Nathas - 2 months ago 5x
Objective-C Question

Use Objective-C code in Swift project which uses Swift code at the same time

I have a Swift project in which I'm using an Objective-C class. I've done this by importing the .h file inside my bridging header.
Everything works fine.

Now I need to use a Swift class inside this Objective-C code, so I imported the $ModuleName-Swift.h inside my Objective-C .h file.
Now Xcode complains that this file wasn't generated.
The interesting part: When I do not import the Objective-C .h file inside the bridging header (so I do not use the Objective-C code in my Swift project) the $ModuleName-Swift.h file works and I can use Swift code inside my Objective-C code.

Is there only a one-way solution for this? (either use swift code in objc or vice versa)



Imported the $ModuleName-Swift.h inside your objc .m file.

If you need your swift class in the objc .h file, write @class YourSwiftClass; after the #import lines in .h file