Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Bridging Header - New Target

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?

like image 414
jaumevn Avatar asked Jul 06 '16 08:07

jaumevn


People also ask

How do I add a bridging header in Swift?

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.

What is a bridging header?

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.

What is Bridge header in Swift?

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.


1 Answers

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.

like image 53
Jerry Avatar answered Oct 10 '22 01:10

Jerry