Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use third party lib in embedded dynamic framework for iOS with swift

Tags:

ios

swift

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

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.

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'

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

like image 229
Mavlarn Avatar asked Nov 19 '14 03:11

Mavlarn


People also ask

What is swift dynamic library?

Dynamic library - . dylib (aka dynamic shared library, shared object, dynamically linked library[doc]) is dynamically linked with the app's executable at load or runtime, but not copied into it. On practice app's package will contain Frameworks folder with . dylib file. All iOS and macOS system libraries are dynamic .

What is the difference between static and dynamic library in Swift?

What are the differences between static and dynamic libraries? Static libraries, while reusable in multiple programs, are locked into a program at compile time. Dynamic, or shared libraries, on the other hand, exist as separate files outside of the executable file.


1 Answers

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.

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.

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. Go to the Dropbox.framework folder in your project direcotry.
  2. Create new folder "Modules" and go inside
  3. Create a file called: "module.modulemap"

The content of the file:

framework module Dropbox {
    umbrella header "Dropbox.h"

    export *
    module * { export * }
}

After doing that I needed to add import path.

  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" ;)

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

Hope this can help you :)

like image 160
Maciej Kosmulski Avatar answered Sep 28 '22 03:09

Maciej Kosmulski