Swift bridging header file won't work with use_frameworks

前端 未结 6 2161
春和景丽
春和景丽 2020-12-30 01:51

I\'m trying to use GoogleidentityToolkit library to handle login an things. I enable use_frameworks! on my pod file, but the module GITkit can\'t be found. I\'m trying to fi

相关标签:
6条回答
  • 2020-12-30 02:13

    The easiest way I've found is to create a fake .swift file within XCode. This should bring up the prompt to automatically create a bridging header.

    1. File > New > File...
    2. For the filetype, choose Swift.
    3. Allow Xcode to manually create the Swift Bridging Header.
    4. Delete the .swift file you originally created.
    0 讨论(0)
  • 2020-12-30 02:15

    A) Create a Bridging 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:

    • "Install objective-c compatibility header" : YES
    • "Objective-C Bridging Header" : path of your bridging header (e.g. "ProjectName/ProjectName-Bridging-Header.h"

    After that you can use the header file to import all your ObjectiveC files which you want use within swift code.

    NOTE: if required set the path as a recursive both in the resource headers and the Swift compiler search section.

    0 讨论(0)
  • 2020-12-30 02:15
    1. Add a new file to Xcode (File > New > File), then select “Source” and click “Header File“.
    2. Name your file “YourProjectName-Bridging-Header.h”.
    3. Create the file.
    4. Navigate to your project build settings and find the “Swift Compiler – Code Generation” section. You may find it faster to type in “Swift Compiler” into the search box to narrow down the results. Note: If you don’t have a “Swift Compiler – Code Generation” section, this means you probably don’t have any Swift classes added to your project yet. Add a Swift file, then try again.
    5. Next to “Objective-C Bridging Header” you will need to add the name/path of your header file. If your file resides in your project’s root folder simply put the name of the header file there. Examples: “ProjectName/ProjectName-Bridging-Header.h” or simply “ProjectName-Bridging-Header.h”.Or, simply drag and drop bridging header file from finder to this empty field. This will automatically add the path of bridging header file.
    6. Open up your newly created bridging header and import your Objective-C classes using #import statements. Any class listed in this file will be able to be accessed from your swift classes.
    0 讨论(0)
  • 2020-12-30 02:25

    None of the answers above worked for me or weren't precise enough. In Xcode 11.4 (Swift 5.2) this solution worked for me:

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

    2. Add all the imports you need to the newly created file.

    3. In Project Navigator click on your project's name.

    4. In the topmost bar choose "Build settings", and in the one a bit lower choose All and Combined.

    5. Search for "Swift Compiler" in the upper right corner

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

    7. All you need to do now is just drag the bridging header file you've created into the pop-up window and hit enter. You're all set!

    *Remember that you'll have to update the path to your Bridging Header every time you project's direct path changes

    0 讨论(0)
  • 2020-12-30 02:27

    Swift 4 and Xcode 9.3

    1. Create a Bridging Header file:

      • Xcode> File/New.../File> Header File
      • Name the file "ProjectName-bridging-header.h"
      • Save to root of your project folder
    2. Xcode> Go to Build Settings (In the project explorer pane select the top most item, should be your project name and in the right pane select the "Build Settings" topic)

      • Just below "Build Setting" make sure "All" and "Combined" is selected
      • In search box type "swift compiler" and find "Objective-C Bridging Header" item
      • Collapse it and double click to the right of it to edit
      • Insert the file name of 1. above -> "ProjectName/ProjectName-bridging-header.h" (note the folder path if bridging file is saved in project folder)
    3. Include the #import 's needed

    0 讨论(0)
  • 2020-12-30 02:28

    First create briding header file with named "projectname-bridging-header.h" at your project root level.

    Now in build settings set your bridging header file path and its objc compatibility header.

    Once done, Clean and build your project its work fine.

    0 讨论(0)
提交回复
热议问题