agentleFS
ThisIsSadeghiThisIsSadeghi/KMPilot/.claude/skills/bridge-swift/SKILL.md

bridge-swift

Skill56 starsChanged 3 months agoMITView on GitHub

Bridge Swift to Kotlin Multiplatform via Interface Injection. Use when integrating iOS SDKs, calling Swift from Kotlin, accessing iOS-only APIs, implementing biometrics/payments/camera, or connecting native frameworks to KMP.

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use Xcode autocomplete (Ctrl+Space) to find exact protocol name.

    line 25

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Bridge Swift

Kotlin interface in iosMain → Swift implements it in iosApp → Inject via Koin DI.

Architecture Reference: @../_shared/patterns.md

When you arrive here

This skill is the iOS-Swift leg of the Rule 14 platform path (@../create-feature/architecture/platform.md). Reach it when a feature's iOS actual can't be written cleanly in Kotlin/Native and needs a Swift class. /create-feature and /modify-feature finish the Kotlin side (the commonMain interface + Android/desktop actuals + expect/actual val platformModule) and then route the user here — they never call this skill directly. Android almost never needs a bridge (Kotlin calls the Android SDK directly), so this is iOS-specific. The Provider-wraps-bridge-in-Either<T> pattern below is the same DataSource contract platform.md describes.

Critical: Swift Inheritance

Swift class inherits from <ModulePrefix><InterfaceName>:

ModuleKotlinSwift Inherits
core:dataRecaptchaBridgeDataRecaptchaBridge
feature:authAuthBridgeAuthAuthBridge

Use Xcode autocomplete (Ctrl+Space) to find exact protocol name.

Implementation Steps

1. Bridge Interface (iosMain)

// <module>/src/iosMain/kotlin/{PKG_PREFIX}/<feature>/<Feature>Bridge.kt
interface <Feature>Bridge {
    suspend fun execute(param: String): String
}

2. Provider (iosMain)

// <module>/src/iosMain/kotlin/{PKG_PREFIX}/<feature>/IOS<Feature>Provider.kt
class IOS<Feature>Provider(private val bridge: <Feature>Bridge) : <Feature>Provider {
    override suspend fun execute(): Either<String> =
        try { Either.Success(bridge.execute("param")) }
        catch (e: Exception) { Either.Failure(ErrorModel.Exception(e)) }
}

3. Swift Implementation (iosApp)

// iosApp/iosApp/<Feature>/<Feature>BridgeImpl.swift
import ComposeApp

class <Feature>BridgeImpl: <ModulePrefix><Feature>Bridge {
    func execute(param: String, completionHandler: @escaping (String?, Error?) -> Void) {
        Task {
            do { completionHandler(try await nativeOperation(param), nil) }
            catch { completionHandler(nil, error) }
        }
    }
}

4. DI Connection

MainViewController.kt (composeApp/src/iosMain/):

fun MainViewController(bridge: <Feature>Bridge) = ComposeUIViewController(
    configure = { initKoin { modules(module { single { bridge } }) } }
) { App() }

ContentView.swift (iosApp/iosApp/):

struct ComposeView: UIViewControllerRepresentable {
    func makeUIViewController(context: Context) -> UIViewController {
        MainViewControllerKt.MainViewController(bridge: <Feature>BridgeImpl())
    }
}

5. Register Provider (iosMain)

// <module>/src/iosMain/kotlin/{PKG_PREFIX}/<feature>/di/Module.ios.kt
internal actual val platformModule = module {
    singleOf(::IOS<Feature>Provider).bind<<Feature>Provider>()
}

6. Export Module

// composeApp/build.gradle.kts
iosTarget.binaries.framework { export(project(":core:data")) }

Signature Mapping

KotlinSwift
suspend fun foo()func foo(completionHandler: @escaping (Error?) -> Void)
suspend fun foo(): Tfunc foo(completionHandler: @escaping (T?, Error?) -> Void)
IntInt32
LongInt64
Boolean (return)KotlinBoolean
Boolean (param)Bool

Validation

./gradlew :composeApp:embedAndSignAppleFrameworkForXcode

Checklist

  • Interface in <module>/src/iosMain/kotlin/{PKG_PREFIX}/<feature>/
  • Provider wraps in try-catch returning Either<T>
  • Swift inherits <ModulePrefix><InterfaceName>
  • Completion handler signature matches exactly
  • MainViewController accepts + registers bridge
  • ContentView passes implementation
  • Module exported in composeApp/build.gradle.kts

Download now (ZIP)

  • Other versions1 project uses a version of this.

    Word for word · 1

    1. ThisIsSadeghi/Loupe★ 1100% same

    Edited · 0

    None found.

    Wrote their own version · 0

    None found.

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository6 other files it gives its agents.

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.