Swift bridging header file will not work with use_frameworks

I am trying to use the GoogleidentityToolkit library to handle login. I turn on use_frameworks! in my pod file, but the GITkit module could not be found. I am trying to understand what is happening. As far as I know, if you use "use_frameworks", you do not need to create any bridge header file, since cocoapods collects the library into one module, so in the future you can import * .swift files as usual.

What do I need to get using the Google Identity Toolkit library in Swift?


This question was asked a week after the release of CocoaPods 1.0.0 (while CocoaPods 0.39.0 was still popular), and the available version of Google Identity Toolkit was 1.1.3 since 2015, but is deprecated in favor of Firebase Authentication ( pod 'FirebaseUI/Auth' ) after Google I / O 2016.

+11
source share
6 answers

A) Create a bridge header file named "ProjectName-Bridging-Header.h" in the root folder of your project.

B) Go to the project build settings and set the following values:

  • "Set objective-c compatibility header": YES
  • "Objective-C Bridging Header": the path of your header (for example, "ProjectName / ProjectName-Bridging-Header.h"

After that, you can use the header file to import all of your ObjectiveC files that you want to use in fast code.

NOTE : if necessary, specify the path as recursive both in the resource headers and in the Swift compiler search section.

+26
source

None of the answers above worked for me or were accurate enough. In Xcode 10.0 ( Swift 4.2 ), this solution worked for me:

1. Create a new header file in the root directory of your project. I'm not sure if the file name really matters, but Apple's automatically generated bridge header files are called "ProjectName-Bridging-Header.h".

2. Add all necessary imports to the newly created file.

3. In Project Navigator, click on the name of your project.

4. In the upper panel, select "Build settings", and in the one below, select All and Combined.

enter image description here

5. Locate the "Swift Compiler" in the upper right corner.

6. Find the "Swift Compiler-General" tab, expand it and double-click the "Objective-C Bridging Header" with the right mouse button.

enter image description here

7. All you have to do now is just drag and drop the bridge header file that you created into the popup window and press Enter. You are all set!

* Remember that you will have to update the bridge header path each time you project direct path changes

+8
source
  • Add a new file to Xcode (File> New> File), then select “Source” and click “Header File”.
  • Name your file "YourProjectName-Bridging-Header.h".
  • Create a file.
  • Go to the settings of your project build and find the "Swift Compiler - Code Generation" section. You can quickly find the “Swift Compiler” in the search box to narrow the results. Note. If you don’t have a Swift Compiler - Code Generation section, it means that you probably don’t have Swift classes added to your project yet. Add a Swift file, then try again.
  • Next to the Objective-C Bridging Header, you will need to add the name / path of your header file. If your file is in the root folder of your projects, just enter the name of the header file. Examples: “ProjectName / ProjectName-Bridging-Header.h” or simply “ProjectName-Bridging-Header.h.” Or just drag and drop the header file from finder to this empty field. This will automatically add the path for linking the header file.
  • Open your newly created bridge header and import the Objective-C classes using the #import statements. Any class specified in this file will be available from your quick classes.
+4
source

The easiest way I've found is to create a fake .swift file in Xcode. This should trigger a hint to automatically create the bridge header.

  • File > New > File ...
  • For file type, select Swift.
  • Allow Xcode to manually create a Swift Bridging Header.
  • Delete the .swift file that you originally created.
+4
source

Swift 4 and Xcode 9.3

  1. Create a bridge header file:

    • Xcode> File / New ... / File> Header file
    • Name the file "ProjectName-bridging-header.h"
    • Save to the root of your project folder
  2. Xcode> Go to Build Settings (in the panel of the project explorer select the topmost item, there should be a name for your project and in the right panel select the theme "Build Settings")

    • Just below “Build Customization” make sure that “All” and “Combined” are selected
    • In the search box, enter "fast compiler" and find the "Objective-C Bridging Header"
    • Collapse it and double-click to its right to change
    • Insert the file name 1. above → " ProjectName /ProjectName-bridging-header.h" (remember the path to the folder if the bridge file is saved in the project folder)
  3. Include the required import

+2
source

First create a shortcut to the header file named "projectname-bridging-header.h" at the root level of your project.

Now in the build settings, specify the path to the bridge header file and its objc compatibility header.

Having done this, clean and build your project to the fullest.

0
source

All Articles