Creating a Bridging Header

2019-07-08 09:33发布

问题:

I am creating a Bridging Header manually since it doesn't let me do it automatically. I created the a header file called "AppName-Bridging-Header.h. The problem is that I can not set it as the project’s Bridging header, which can be normally done through the project’s build settings. I do not have the Objective-C Bridging file section under Swift Compiler -Code generation. I only have Optimization level. Thank you.

回答1:

Your question is a bit unclear but I'll try to help you as much as I can.

1) To create a bridging header, there are two different ways :

  • With the help of Xcode : When you add a file to your project, Xcode asks if you want to create a bridging header.
  • Manually : You have to create a header file and name it Your Project-Bridging-Header.h (This is the general syntax)

2) Link the header :

  • If Xcode created the bridging header it is automatically linked under : -> Build Settings -> Swift Compiler - Code Generation -> Objective-C Bridging Header
  • If you created manually you have to go here under the "Build Settings" tab and then search for "Bridging Header. Here then you have the row "Objective-C Bridging Header" and you just have to put the the name of the folder he's in and his name. Like that : Your Project/Your Project-Bridging-Header.h. The name of the folder is defined as the screenshot shows. Doesn't matter if the project name (first arrow) and the first box (second arrow) are different, just take the right one.

Hope this helps someone :) Sorry for explaining from the start as it is not asked in the question but sometimes it is good to have the all way of doing