I have an objective-c project with one class implemented in Swift. The project has with two targets: A and B. For both of them the Xcode created the bridging header files, A-Swift.h
and B-Swift.h
, and the app builds and runs both targets without any issue.
I've added two new targets, C and D (this time no bridging header files were created). If I build A and B there is no issue, but if I build C and D the build isn't completed because it can't find the B-Swift.h
.
Target C is just a duplication of A, and D a duplication of B, with of course some properties updated in the plist file.
Any suggestion?
Alternatively, you can create a bridging header yourself by choosing File > New > File > [operating system] > Source > Header File. Edit the bridging header to expose your Objective-C code to your Swift code: In your Objective-C bridging header, import every Objective-C header you want to expose to Swift.
The bridging header allows the use of Swift and Objective-C in the same project. There are no downsides to having a bridging header in your project as the two languages can work well together within the same app.
You can use Objective-C and Swift files together in a single project, no matter which language the project used originally. This makes creating mixed-language app and framework targets as straightforward as creating an app or framework target written in a single language.
I suggest using the same generated header name for different targets. Otherwise you'd need to include all generated headers in each .m
file or change the import based on target you run.
You can go to Build Settings
-> Swift Compiler General
and change Objective-C Generated Interface Header Name
to A-Swift.h
for all your targets.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With