Mobile Development 18 min read

Practical Experience of Swift/Objective‑C Binary Mixed Compilation at Kuaishou Overseas Client Team

This article shares the Kuaishou overseas client team's practical experiences and solutions for improving compilation efficiency through Swift/Objective‑C binary mixed compilation, covering single‑target and multi‑target strategies, moduleization challenges, binary compatibility, and future directions for mobile development.

Kuaishou Tech
Kuaishou Tech
Kuaishou Tech
Practical Experience of Swift/Objective‑C Binary Mixed Compilation at Kuaishou Overseas Client Team

Background

Swift has become the primary language for macOS and iOS, replacing Objective‑C. The Kuaishou overseas client team accumulated extensive Swift and Objective‑C mixed‑code experience across projects such as Kwai‑Pro, MV Master, and Zynn. To further improve compilation efficiency, they explored binary mixed compilation of Swift and Objective‑C, solving many practical problems.

Single‑Target Mixed Compilation

In a single target, a bridging header is set in the Build Settings, allowing Swift to access Objective‑C and generating a -Swift.h file for Objective‑C to call Swift. However, this method disables Swift version compatibility flags, so the team recommends using OTHER_SWIFT_FLAGS = -import-underlying-module together with HEADER_SEARCH_PATHS for Swift to access Objective‑C interfaces.

Multi‑Target Mixed Compilation

When each Pod component is compiled in its own target, the team faced several challenges:

OC components need to be Clang modules; otherwise, module‑related compilation errors arise.

Some Pods cannot be modularized due to legacy code, requiring work‑arounds such as “FakeFramework” to resolve dependency and compilation order issues.

Macro usage inside modules can pollute the calling code’s context, so missing macros must be set on the consuming target.

Solutions include enabling modular_header = true in the Podfile, using #import <Framework/FrameworkHeader.h> style imports, flattening header hierarchies, and adding appropriate -fmodule-map-files and -Xcc flags to OTHER_CFLAGS and OTHER_SWIFT_FLAGS .

Binary Compatibility of Swift Components

Swift modules generated by different compiler versions are incompatible. Since Swift 5.1, the BUILD_LIBRARY_FOR_DISTRIBUTION flag produces a swiftinterface file, a textual representation that remains compatible across compiler versions, solving binary compatibility issues.

Binary Mixed Compilation

Pre‑compiled binary static libraries are packaged as XCFrameworks, with module information (modulemap, swiftinterface) included. This enables stable Swift/Objective‑C binary mixed compilation. The team also created “FakeFramework” structures during pod install to provide necessary headers and module maps before actual compilation, mitigating ordering problems.

Future Outlook

The team plans to standardize base library usage, expose public headers properly, and increase the proportion of modularized components to improve compile performance and maintainability.

iOSCocoaPodsSwiftObjective-CModuleMixed Compilation
Kuaishou Tech
Written by

Kuaishou Tech

Official Kuaishou tech account, providing real-time updates on the latest Kuaishou technology practices.

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.