使用Swift项目中用Objective-c编写的库类

时间:2022-09-07 08:51:27

I have a Swift project in which i want to use an sdk which is in a form of library files .a and .h files (written in Objective-C)

我有一个Swift项目,其中我想使用一个sdk,它是一种库文件.a和.h文件(用Objective-C编写)

How do i use the code inside my swift project?

我如何在swift项目中使用代码?

When i add the files to my project it dont give the option to create an objective-c bridging header

当我将文件添加到我的项目时,它不提供创建objective-c桥接头的选项

1 个解决方案

#1


0  

To create a bridging header:

要创建桥接标头:

  1. Add a new Header file to your project. File -> New -> Header file. I named it: "Your-Header-file.h"
  2. 将新的Header文件添加到项目中。文件 - >新建 - >头文件。我把它命名为:“Your-Header-file.h”
  3. Go to your project Target -> Build Settings, search for Objective-C Bridging Header and set the header file's path in this field. You can do this by double-click Objective-C Bridging Header field, a panel show up, drag the header file to this panel.
  4. 转到您的项目Target - > Build Settings,搜索Objective-C Bridging Header并在此字段中设置头文件的路径。您可以通过双击Objective-C Bridging Header字段,显示一个面板,将头文件拖到此面板来完成此操作。

使用Swift项目中用Objective-c编写的库类

  1. include .h file you need to use in Your-Header-file.h.
  2. 包含你需要在Your-Header-file.h中使用的.h文件。

#1


0  

To create a bridging header:

要创建桥接标头:

  1. Add a new Header file to your project. File -> New -> Header file. I named it: "Your-Header-file.h"
  2. 将新的Header文件添加到项目中。文件 - >新建 - >头文件。我把它命名为:“Your-Header-file.h”
  3. Go to your project Target -> Build Settings, search for Objective-C Bridging Header and set the header file's path in this field. You can do this by double-click Objective-C Bridging Header field, a panel show up, drag the header file to this panel.
  4. 转到您的项目Target - > Build Settings,搜索Objective-C Bridging Header并在此字段中设置头文件的路径。您可以通过双击Objective-C Bridging Header字段,显示一个面板,将头文件拖到此面板来完成此操作。

使用Swift项目中用Objective-c编写的库类

  1. include .h file you need to use in Your-Header-file.h.
  2. 包含你需要在Your-Header-file.h中使用的.h文件。