Search code examples
swiftrealmcocoapods

Using static libraries in Swift with CocoaPods fails for Realm


Since Xcode 9 it is possible to use static libraries by omitting the use_frameworks! flag in the Podfile. However, when used with the Pod RealmSwift this results in the following error:

[!] The following Swift pods cannot yet be integrated as static libraries:

The Swift pod `RealmSwift` depends upon `Realm`, which do not define modules. To opt into those targets generating module maps (which is necessary to import them from Swift when building as static libraries), you may set `use_modular_headers!` globally in your Podfile, or specify `:modular_headers => true` for particular dependencies.

Sadly, the proposed solution with use_modular_headers! does not work.

Other things I have tried include:

  • Using the latest Realm version (3.15.0)
  • Use the Objective C version and add Swift support, this won't build and give a module not found error in the RLMSupport.swift file .
  • Adding a bridging header for the Objective C version.
  • Endless clean, rebuild, Xcode relaunches and Derived Data folder cleaning.

It would not be preferable to circumvent CocoaPods and have this dependency be installed in a separate way, since that would make updating a more complex process. I hope there is a solution that works with CocoaPods, Realm and Swift.


Solution

  • I did the job doing following:

    pod 'RealmSwift', '~> 3.17', :modular_headers => true
    pod 'Realm', '~> 3.17', :modular_headers => true