Search code examples
iosswiftxcodecocoapodslottie

problem integrating ObjC pod into a Swift framework


the setup

I have an iOS App MY-App which uses my own framework MY-Framework. Both are written in swift. The app only handles user authentification and passes an access token to MY-Framework. MY-Framework then handles the entire ScreenFlow and business logic. The goal is to distribute the MY-Framework to customers to use it in their apps.

a minimal sample of the project setup exhibiting this problem is available here: https://github.com/vprimachenko/lottie-pod-problem-sample

now I was to enhance my framework provided views with some animations and were to use for it. i am using version1.6.0-pre

Naïve attempt

i created a Podfile with following content

target 'fw' do
  pod 'lottie-ios'
end

which resulted in a compile error in the framework

./fw/fw/File.swift:4:8: error: no such module 'Lottie'
import Lottie
       ^

frameworks

after some googling i changed my Podfile to:

target 'fw' do
  use_frameworks!
  pod 'lottie-ios'
end

result: Runtime crash

dyld: Library not loaded: @rpath/Lottie.framework/Lottie
  Referenced from: .../Build/Products/Debug-iphonesimulator/fw.framework/fw
  Reason: image not found

modular headers maybe?

release notes mention use_modular_headers!, lets try that:

target 'fw' do
 use_modular_headers!
 pod 'lottie-ios'
end

result: compiler error in the containing app

./app/app/ViewController.swift:3:8: error: missing required module 'Lottie'
import fw
      ^

maybe both?

target 'fw' do
 use_modular_headers!
 use_frameworks!
 pod 'lottie-ios'
end

result: runtime crash

dyld: Library not loaded: @rpath/Lottie.framework/Lottie
 Referenced from: .../Build/Products/Debug-iphonesimulator/fw.framework/fw
 Reason: image not found

the hack

after some trying around I was able to solve the situation by providing my own bringing header for Lottie but this feels more like a duct-tape rather than a proper solution. I will still post this later as an additional answer.

My Question

how do i use properly integrate lottie-ios cocoapod in such a way that it is completely contained in MY-Framework, so when i share it to a customer they can just drop it into their App and not worry about any dependencies?

Releasing it as a private pod with dependencies is sadly not an option.


Solution

  • The common way to use objective-c code in swift is using bridging headers, take a look at this:

    Importing Objective-C into Swift

    you need to create a bridging header and add it to your project then inside the .h file you created simply add :

    #import <Lottie/Lottie.h>