Mobile Development 7 min read

Converting CocoaPods and Carthage Dependencies to Static Libraries in an iOS Swift Project

This article explains how the Egg Roll Fund iOS project migrated its mixed CocoaPods and Carthage dependencies from dynamic frameworks to static libraries using CocoaPods 1.5’s use_modular_headers! flag, manual bridging‑header adjustments, and a Carthage static‑library script, resulting in faster startup and smaller app size.

Snowball Engineer Team
Snowball Engineer Team
Snowball Engineer Team
Converting CocoaPods and Carthage Dependencies to Static Libraries in an iOS Swift Project

Egg Roll Fund, an independent fund‑sales platform under Snowball, has been using Swift since version 2.0 and awaited the static‑linking feature that arrived with Xcode 9, enabling Swift static libraries.

Dynamic libraries on iOS are discouraged because they increase app launch time and can cause dyld crashes on older devices such as iOS 9.

The project manages dependencies with a mix of CocoaPods and Carthage, so both needed to be converted to static libraries. The timing was ideal because CocoaPods 1.5 introduced support for Swift static libraries via the use_modular_headers! flag.

CocoaPods

After upgrading to the latest CocoaPods, the Podfile was changed by removing use_frameworks! and adding use_modular_headers! . The subsequent pod install produced errors caused by circular references between bridging‑header imports and library modules.

The fix was simply to delete the dependent library imports from the bridging header. The new use_modular_headers! flag makes all pods modular, allowing direct import in Swift without a bridging header.

CocoaPods 1.5 also relaxed the forced modular conversion, preventing header‑search‑path conflicts that previously required setting DEFINES_MODULE = true for static libraries.

iOS static libraries include both static libraries and static frameworks, while dynamic libraries have their dynamic counterparts. Frameworks are bundles that can contain resources such as xibs, images, and property lists; an umbrella framework is a framework that contains other frameworks, as used by CocoaPods.

Umbrella headers and modular headers are concepts from the LLVM module system; Swift’s module system is a customized version of this. For more details see the referenced articles on Modules for Swift.

After removing the bridging‑header imports, developers must manually add import statements for each library at the top of Swift files because Swift hides namespaces for imported Objective‑C code.

If an Objective‑C file in the project imports a modular library, a “modular header not defined” error occurs. The remedy is to set modular_headers = false for that library or convert the code to Swift.

With these changes, the CocoaPods dependencies are now statically linked.

Carthage

Carthage does not yet support Swift static libraries natively, but a Python script using libtool can create them; the resulting static libraries are added to “Link Binary With Libraries” without embedding them in a framework.

Results

All libraries were statically packaged; on an iPhone 6 Plus the launch‑time overhead dropped from over 5900 ms to about 1300 ms.

App size decreased: the download package went from 35.2 MB to 30 MB and the installed package from 57.9 MB to 46.9 MB.

References

Optimizing App Startup Time – WWDC 2016

Crash example – GitHub issue

CocoaPods Blog – CocoaPods 1.5.0 release notes

Dynamic Library Programming Topics – Apple Documentation

Umbrella Header in Frameworks – blog post

Modules for Swift – blog article

Recruitment Note

Snowball’s engineering team is hiring Java engineers, operations developers, test developers, and algorithm engineers; interested candidates can view the original posting for details.

Mobile developmentiOSCocoaPodsSwiftstatic librariesCarthage
Snowball Engineer Team
Written by

Snowball Engineer Team

Proactivity, efficiency, professionalism, and empathy are the core values of the Snowball Engineer Team; curiosity, passion, and sharing of technology drive their continuous progress.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.