如何在swift的iOS嵌入式动态框架中使用第三方库 [英] How to use third party lib in embedded dynamic framework for iOS with swift

查看:303
本文介绍了如何在swift的iOS嵌入式动态框架中使用第三方库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我有一个项目,比如testApp,使用像alamofire这样的第三方库和其他一些目标c中的库。

Now I have a project, like testApp, using some third party lib like alamofire and some others libs in objective-c.

现在我想添加一个小部件。根据一些教程,我创建了一个新目标testAppKit作为共享动态框架,并将testAppWidget作为今天的扩展。公共代码将在testAppKit中重用。

Now I want to add a today widget. According to some tutorial, I created a new target "testAppKit" as a shared dynamic framework, and target "testAppWidget" as today extension. The common code will be in testAppKit for reuse.

现在我需要在testAppKit中使用第三方库。并在testAppKit的构建阶段添加了lib和header。然后我在testAppKit.h中添加 #import< theLib / TheHeader.h> 。但是有一个错误:

Now I need to use third party libs in testAppKit. And added lib and header in build phases of testAppKit. Then I add #import <theLib/TheHeader.h> in testAppKit.h. But there is an error:

Include of non-modular header inside framework module 'testAppKit'

所以,我想知道如何在这种嵌入式动态框架中使用第三方库(可能在Swift或Objective-C中)。

So, I want to know how to use third party libs (maybe in Swift or Objective-C) in this kind of embedded dynamic framework.

推荐答案

我在我的应用程序中使用Dropbox Datastore API,最后我使用它来嵌入Cocoa Touch框架来共享包含App的代码和今天的扩展。

I use Dropbox Datastore API in my app and I finally made it working for embedded Cocoa Touch framework to share code for Containing App and Today Extension.

我发现在我的嵌入式框架的Swift文件中,我可以导入我在项目中的任何第三方框架(即Farbic.framework,Crashlytics)等)但不是Dropbox。

I figured out that in my Swift file in the embedded framework I can import any 3rd party framework I had in the Project (i.e. Farbic.framework, Crashlytics etc.) but not Dropbox.

有什么区别? 模块文件夹! Dropbox.framework不提供模块映射文件。所以我根据Fabric.framework中的内容创建了它:

What was the difference? The "Modules" folder! Dropbox.framework doesn't provide module map file. So I created it based on what I found in Fabric.framework:


  1. 转到项目目录中的Dropbox.framework文件夹。

  2. 创建新文件夹Modules并进入内部

  3. 创建一个名为module.modulemap的文件

文件内容:

framework module Dropbox {
    umbrella header "Dropbox.h"

    export *
    module * { export * }
}

执行此操作后,我需要添加导入路径。

After doing that I needed to add import path.


  1. 转到您的项目文件

  2. 选择嵌入式框架目标

  3. 转到构建设置并找到Swift编译器 - 搜索路径

  4. 添加路径到你的Dropbox.framerowk并设置递归选项。

  1. Go to your Project file
  2. Select your embedded framework target
  3. Go to the "Build Settings" and find "Swift Compiler - Search Paths"
  4. Add path to your Dropbox.framerowk and set "recursive" option.

我想在这里放一个截图,但我可以'这样做 - 因为我的声誉;)

I wanted to put a screenshot here but I can't do that yet - because of my "reputation" ;)

现在我可以在我的swi中执行导入Dropbox ft文件:)

Now I'm able to do "import Dropbox" in my swift files :)

希望这可以帮助你:)

这篇关于如何在swift的iOS嵌入式动态框架中使用第三方库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆