我想在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)。
这是示例项目的一些屏幕截图,其中包含我的了解和不了解的内容:
我想在我的Swift代码中使用的lib方法的原型的Bridging-Header-File文件(我不喜欢这样,但是如果这是唯一的方法……)。
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.
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
.
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 ?
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 :
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.
然后创建一个新的.m文件,将其重命名为.mm并SuperpoweredRecorderWrapped
在其上实现。我同时导入SuperpoweredRecorderWrapped.h
和SuperpoweredRecorder.h
。我创建一个SuperpoweredRecorder
对象作为属性命名,_wrapped
并在我的方法中调用该_wrapped
对象的相应方法。就这样,当我打电话start
的SuperpoweredRecorderWrapped
在我的银行代码,这人会打电话start
的_wrapped
,一个SuperpoweredRecorder
对象。看到了把戏吗?
最后,我将所有包装的类都包含在Bridging-Header中,这样我就可以从Swift实例化包装的对象。
注意:所有C ++代码都必须保存在.mm文件中,这就是为什么我将#include
.h包含在.mm文件而不是.h文件中的包含C ++代码的原因。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句