Skip to content

Tips

Reduce Build Time

  • Since the version 0.4.0

spmWorkingPath has been added to change the path to Swift Package working file.

By setting spmWorkingPath outside the build folder, the working files won't be removed if you clean the project, and you can exclude the folder from indexing.

Swift Package Manager has its own cache, so it's fine to detach it from the Kotlin build folder.

CI/CD Caching

Add to your cache the content of the build/spmKmpPlugin folder or the spmWorkingDir value if set.

Also, check my GitHub action workflow where I build the example app with cached built files.

Firebase

An full example of how to implement Firebase with the plugin

Working With 'objcnames.classes' Types

For example, when using a UIView (work with any ObjC Types, ex: UIViewController...).

mySwiftBridge.swift
// Force cinterop to include `platform.UIKit.UIView`
@objcMembers public class MyDummyView: UIView {}

// Or force by inheritance
@objcMembers public class TestClass: NSObject /* or UIView */ {

    // return `UIView` is not enough to let cinterop use the correct type
    public func getView() -> UIView {
        return UIView()
    }

    public func setView(view: UIView) {
        // store view
    }

    // or if you don't want to declare an extra MyDummyView

    public func getViewWithNSObject() -> NSObject {
        return UIView()
    }

    public func setViewWithNSObject(view: NSObject) {
        // store view
    }

}
iosMain/myKotlinFile.kt
fun getView(): UIView = TestClass().getView()
fun setView(view: UIView) = TestClass().setViewWithView(view)

// or

fun getView(): UIView = TestClass().getViewWithNSObject() as UIView
fun setView(view: UIView) = TestClass().setViewWithNSObject(view)

Support Xcode 15 and earlier

Experimental

This is experimental; this tips is not fully tested for every use cases. You can create an issue if needed.

As Xcode < 16 is unstable with Swift Package and has some weird behavior. It's recommended to use the latest version of the IDE.

But, it is possible to support older versions of Xcode by using a more recent version of the Swift Compiler than the Xcode one.

The property swiftBinPath has been added to change the swift command used by the plugin.

This official tool swiftly has been recently added to easily install another version of swift on macOS.

So follow the swiftly guide to install another swift version and set the swiftBinPath property correctly.

swiftBinPath = "/path/to/.swiftly/bin/swift"