Swift桥接头文件不会工作

[英]Swift bridging header file wont work


Im trying to use GoogleidentityToolkit library to handle login an things. I enable use_frameworks! on my pod file, but the module GITkit cant be found. I'm trying to figure out whats going. As far as I know if you use "use_frameworks" you don't need to create any bridging header file, since cocoapods compiles down the library into a single module, so later you can imported as usual on your*.swift files.

我试图使用GoogleidentityToolkit库来处理登录的事情。我启用use_frameworks!在我的pod文件上,但找不到模块GITkit。我想知道最新情况。据我所知,如果使用“use_frameworks”,则不需要创建任何桥接头文件,因为cocoapods将库编译成单个模块,因此稍后您可以像往常一样导入* .swift文件。

What do I need to get using Google Identity Toolkit library in swift?.

在swift中使用Google Identity Toolkit库需要什么?

6 个解决方案

#1


23  

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

A)在项目的根文件夹中创建名为“ProjectName-Bridging-Header.h”的桥接头文件。

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

B)转到项目构建设置并设置以下值:

  • "Install objective-c compatibility header" : YES
  • “安装objective-c兼容标头”:是
  • "Objective-C Bridging Header" : path of your bridging header (e.g. "ProjectName/ProjectName-Bridging-Header.h"
  • “Objective-C Bridging Header”:桥接头的路径(例如“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.

之后,您可以使用头文件导入要在swift代码中使用的所有ObjectiveC文件。

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

注意:如果需要,在资源头和Swift编译器搜索部分中将路径设置为递归。

#2


4  

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.

我发现最简单的方法是在XCode中创建一个假的.swift文件。这应该会提示自动创建桥接头。

  1. File > New > File...
  2. 文件>新建>文件...
  3. For the filetype, choose Swift.
  4. 对于filetype,选择Swift。
  5. Allow Xcode to manually create the Swift Bridging Header.
  6. 允许Xcode手动创建Swift Bridging Header。
  7. Delete the .swift file you originally created.
  8. 删除最初创建的.swift文件。

#3


3  

  1. Add a new file to Xcode (File > New > File), then select “Source” and click “Header File“.
  2. 将新文件添加到Xcode(文件>新建>文件),然后选择“源”并单击“标题文件”。
  3. Name your file “YourProjectName-Bridging-Header.h”.
  4. 将文件命名为“YourProjectName-Bridging-Header.h”。
  5. Create the file.
  6. 创建文件。
  7. 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.
  8. 导航到项目构建设置并找到“Swift编译器 - 代码生成”部分。您可能会发现在搜索框中键入“Swift Compiler”以缩小结果范围会更快。注意:如果您没有“Swift编译器 - 代码生成”部分,这意味着您可能还没有向项目中添加任何Swift类。添加Swift文件,然后重试。
  9. 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.
  10. 在“Objective-C Bridging Header”旁边,您需要添加头文件的名称/路径。如果您的文件位于项目的根文件夹中,只需将头文件的名称放在那里。示例:“ProjectName / ProjectName-Bridging-Header.h”或简称为“ProjectName-Bridging-Header.h”。或者,只需将查找器中的桥接头文件拖放到此空字段即可。这将自动添加桥接头文件的路径。
  11. 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.
  12. 打开新创建的桥接头,并使用#import语句导入Objective-C类。可以从swift类中访问此文件中列出的任何类。

#4


3  

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

上面的答案都不适合我,或者不够精确。在Xcode 9.4.1(Swift 4)中,这个解决方案对我有用:

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".

1.在项目的根目录中创建一个新的头文件。我不确定文件的名称是否真实重要,但Apple自动生成的桥接头文件名为“ProjectName-Bridging-Header.h”。

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

2.将所需的所有导入添加到新创建的文件中。

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

3.在Project Navigator中,单击项目的名称。

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

4.在最上面的栏中选择“构建设置”,在较低的栏中选择“全部”和“组合”。

enter image description here

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

5.在右上角搜索“Swift Compiler”

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

6.找到“Swift Compiler- General”选项卡,展开它,然后双击“Objective-C Bridging Header”的右侧。

enter image description here

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!

7.您现在需要做的就是将您创建的桥接头文件拖到弹出窗口中并按Enter键。你们都准备好了!

#5


2  

Swift 4 and Xcode 9.3

Swift 4和Xcode 9.3

  1. Create a Bridging Header file:

    创建桥接头文件:

    • Xcode> File/New.../File> Header File
    • Xcode>文件/新建... /文件>标题文件
    • Name the file "ProjectName-bridging-header.h"
    • 将文件命名为“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)

    Xcode>转到Build Settings(在项目浏览器窗格中选择最顶层的项目,应该是您的项目名称,并在右侧窗格中选择“Build Settings”主题)

    • Just below "Build Setting" make sure "All" and "Combined" is selected
    • 在“Build Setting”下方,确保选中“All”和“Combined”
    • In search box type "swift compiler" and find "Objective-C Bridging Header" item
    • 在搜索框中键入“swift compiler”并找到“Objective-C Bridging Header”项
    • 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)
    • 在上面插入文件名1. - >“ProjectName / ProjectName-bridging-header.h”(如果桥接文件保存在项目文件夹中,请注意文件夹路径)
  3. Include the #import 's needed

    包括#import所需

#6


0  

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

首先在项目根级别创建名为“projectname-bridging-header.h”的briding头文件。

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

现在在构建设置中设置桥接头文件路径及其objc兼容性头。

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

完成后,清理并构建您的项目工作正常。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2016/05/17/d4ee49e32a0aaa418fc4ec3cd995e7d.html



 
© 2014-2018 ITdaan.com 粤ICP备14056181号