To integrate a Kotlin Multiplatform (KMP) shared module into an iOS app, you must generate an iOS framework from the shared module and add it as a dependency to the iOS project. There are two primary integration strategies:
1. Local Integration
Use local integration if you want full control over the entire codebase and want instant updates to your final applications whenever the common code changes.
Options for Local Integration:
- Direct integration: Connects the framework directly via an Xcode build phase script. Best if you do not use CocoaPods dependencies in your KMP project. This is the default if using the Kotlin Multiplatform IDE plugin.
- SwiftPM integration with a local package: Best for monorepo setups using Swift Package Manager and where you don't have irreplaceable CocoaPods dependencies.
- CocoaPods integration with a local podspec: Best for monorepo setups using CocoaPods or if your KMP project imports CocoaPods dependencies.
2. Remote Integration
Use remote integration if you want to explicitly separate the shared code codebase from the final application codebase. The shared code is treated like a regular third-party dependency.
Options for Remote Integration:
- SwiftPM with XCFrameworks: Export your KMP project as an XCFramework and distribute it as a remote Swift package.
- CocoaPods integration with XCFrameworks: Build XCFrameworks using the Kotlin CocoaPods Gradle plugin and distribute them via CocoaPods.