- Integrate Cocoapods plugin for Kotlin Native
See shared/build.gradle
for cocoapods plugin setup. Note that setting version
is required:
// CocoaPods requires the podspec to have a version.
version = 1.0
Also note the kotlin.cocoapods { ... }
block.
The Cocoapods plugin will automatically build frameworks for both debug and release variants. No need to run any custom gradlew tasks to pack for Xcode, scripts to run, etc.
If you get stuck, refer to this commit
Note: if you prefer to run Gradle tasks to pack framework for xcode instead, refer to these detailed instructions
-
Run
./gradlew :shared:podspec
from the root of the project to generateshared/shared.podspec
which contains kotlin targets for iOS (this includes simulator and device). -
Create XCode project in
iosApp
-
Close XCode.
-
Inside the new project created run
pod init
-
Edit the generated
Podfile
to point to theshared.podspec
:
target 'KmpGithub' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for KmpGithub
pod 'shared', :path => '../../shared'
end
-
Run
pod install
inside the XCode project folder. -
Open the project in XCode by executing
open <proj-name>.xcworkspace
from your ios project root folder. -
Use
import shared
in your code and utilize shared Kotlin code from Swift! If there are any build errors, try building the project by running in iOS simulator.