如何在Swift项目中使用Superpowered lib

尤安

我想在Swift中制作一个应用程序,该应用程序只需通过iPhone的麦克风进行录制,然后播放录制的声音。

为此,我想使用lib Superpowered这个带有头文件的静态库。

为此,我尝试将.a和标头文件拖放到我的项目中(Xcode为我创建了一个桥接标头文件),将.a添加到Xcode> Target> General中的“ Linked Frameworks and Libraries”中。 Xcode>目标>构建阶段>“也将二进制文件链接到库”),然后在Xcode>目标>构建设置>搜索路径>库搜索路径中索引.h文件路径。

但是与此同时,我遇到了错误“ ld:找不到体系结构arm64的符号”与此处完全相同XCode:体系结构arm64错误的未定义符号,我尝试了在网上找到的所有解决方案,但仍然没有编译方式。

所以!

Superpowered为我们提供了一个示例应用程序,以展示如何在Swift项目中混合使用Objective-C ++并使用它们的lib(如果您希望https://github.com/superpoweredSDK/Low-Latency-Android-Audio- iOS-Audio-Engine)。

这是示例项目的一些屏幕截图,其中包含我的了解和不了解的内容:

桥接头文件Superpowered

我想在我的Swift代码中使用的lib方法的原型的Bridging-Header-File文件(我不喜欢这样,但是如果这是唯一的方法……)。

ViewController文件

The viewController file where the code in Swift is, and where I can create a Superpowered object thank's to the Bridging-Header-File, and call the methods that I've put in it.

.mm文件

And wtf I don't even understand why this Objective-C++ file is here and what it contains. It comes out from nowhere, not even their lib files.

So with this sample project in mind, I've created my own project, here is some screenshots :

桥接头文件

The same Bridging-Header-File that in the sample project except that I include SuperpoweredIOSAudioIO.h so I can use SuperpoweredIOSAudioIODelegate.

viewController

My viewController file where the code in Swift is, and where I can create a Superpowered object thank's to the Bridging-Header-File, and call the methods that I've put in it.

Until here, it's great, except that I can't for exemple create a SuperpoweredRecorder object. If I try to include the SuperpoweredRecorder.h file in my Bridging-Header-File I have these errors :

错误

So I saw that it is because SuperpoweredRecorder.h includes some .cpp files and I have to create a wrapper for cpp (a little bit like I did with the bridging header, no ?) but that includes a .h and a .mm file and I don't know what I have to put in that .mm file (the code of SuperpoweredRecorder.cpp ? But I don't have access to it)

So yes, I'm a little bit confused with all that stuff, can you help me to understand how can I use all the Superpowered lib in my Swift project please ?

YoanGJ

As I said in comment to @OmniProg, I had a little conversation with the CTO of Superpowered that helped me a lot to find the solution below.

So, as Swift cannot interact directly with C++ but can with Objective-C, I had to create objects in Objective-C++ (.mm file, a mix between C++ and Objective-C) that wrap C++ classes of the lib Superpowered.

Here is an example with the SuperpoweredRecorder object from the lib :

SuperpoweredRecorderWrapped.h

Here I create a .h file where I prototype my wrapper with the name SuperpoweredRecorderWrapped, and I also prototype in it all the methods of the SuperpoweredRecorder of the lib that I want to use.

SuperpoweredRecorderWrapped.mm

然后创建一个新的.m文件,将其重命名为.mm并SuperpoweredRecorderWrapped在其上实现我同时导入SuperpoweredRecorderWrapped.hSuperpoweredRecorder.h我创建一个SuperpoweredRecorder对象作为属性命名,_wrapped并在我的方法中调用该_wrapped对象的相应方法就这样,当我打电话startSuperpoweredRecorderWrapped在我的银行代码,这人会打电话start_wrapped,一个SuperpoweredRecorder对象。看到了把戏吗?

Bridge-Header

最后,我将所有包装的类都包含在Bridging-Header中,这样我就可以从Swift实例化包装的对象。

注意:所有C ++代码都必须保存在.mm文件中,这就是为什么我将#include.h包含在.mm文件而不是.h文件中的包含C ++代码的原因。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在多模块Java项目中使用lib commons-dbcp2(BasicDataSource类)时出错

在python中使用cpp项目的dll和.lib文件

什么是.exp文件和.lib文件,如何在我的C#项目中使用它们?

如何在Swift项目中使用ECSlidingViewController

如何在Swift项目中使用TPKeyboardAvoiding?

在新的堆栈项目中,如何在src / Lib.hs和app / Main.hs之间拆分代码?

在Cmake中使用C中的pthread lib

如何在我的Swift项目中使用Objective-C项目

如何在MSVC 2015解决方案中的所有项目中添加include / lib目录?

从带有pub的项目中运行lib的lib build

在lib / file.rb中使用ApplicationHelper

如何在派生的lib中使用DefinetelyTyped?

如何在C ++项目中使用Swift静态库(.a)?

在/ usr / local / lib中使用共享库

如何在C#项目中使用LIB文件?

如何在静态lib中使用opengl?

如何在项目中使用Printf

在python中使用pygame lib流视频

使用Pod lib create for OS X项目

如何在MATLAB MEX文件中使用FFTW lib文件?

如何在/ usr / lib / systemd /中使用systemd服务?

/ var / lib是如何命名的?

如何在Swift tvOS项目中使用TVML文档?

如何在我的项目中添加Orchid(Tor Java Lib)?

如何在 C++ 项目中使用非托管的 .dll、.lib、.exp

不能在其他项目中使用自定义视图(aar lib)

Ruby 项目中“lib”目录的常规用途是什么?

如何在 SMT-lib 中使用元组?

如何在 VS 2019 或 CLion 项目中使用“webrtc.lib”静态库?