Architectural Invariant Design: KMP 2.1 and Swift 6 Strict Concurrency Isolation and Sendable Interop Boundary
KMP 2.1 and Swift 6 Strict Concurrency Isolation and Sendable Interop Boundary defines an industrial-grade behavioral standard for mobile engineering. Enforces complete data race safety across the Kotlin Multiplatform 2.1 and Swift 6 language boundary by isolating Objective-C export interfaces within strict Swift actors. Prevents passing non-Sendable Kotlin reference types across asynchronous boundaries and mandates thread-safe Sendable DTO contracts or SKIE-generated Swift concurrency wrappers for all exported Coroutine flows and suspend functions. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.
Hazard Analysis: What Breaks Without This Rule
The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:
| Failure Mode | AI Symptom (The Anti-Pattern) | Severity | Production Impact & Remedy |
|---|---|---|---|
| AI Hallucination & Deprecation Drift | Passing Non-Sendable Kotlin Reference Types and Unisolated Completion Handlers Across Swift 6 Actor Boundaries | Critical | Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production. Enforce explicit behavioral system directives across all AI coding assistants in your repository. |
| Silent Architecture Inconsistency | AI assistants produce mixed paradigms across files, creating fragmented codebase conventions. | Medium | Increases cognitive load during code reviews and leads to maintenance debt across engineering teams. Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails. |
Step-by-Step Production Directives
Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:
Engineers MUST ALWAYS compile Swift targets with `SWIFT_STRICT_CONCURRENCY = complete` to catch bridge-crossing Sendable violations at compile-time.
Engineers MUST ALWAYS compile Swift targets with `SWIFT_STRICT_CONCURRENCY = complete` to catch bridge-crossing Sendable violations at compile-time.
Engineers MUST NOT pass raw Kotlin mutable reference classes across Swift actor boundaries without an explicit Swift actor isolation or `@Sendable` value-type transformation.
Engineers MUST NOT pass raw Kotlin mutable reference classes across Swift actor boundaries without an explicit Swift actor isolation or `@Sendable` value-type transformation.
Engineers MUST ensure all bridged Kotlin suspend functions invoked from Swift 6 are isolated to the caller's actor (typically `@MainActor`) or wrapped in an actor-isolated facade.
Engineers MUST ensure all bridged Kotlin suspend functions invoked from Swift 6 are isolated to the caller's actor (typically `@MainActor`) or wrapped in an actor-isolated facade.
Kotlin shared domain models intended for Swift cross-boundary dispatch MUST be deeply immutable (consisting solely of primitive types, immutable strings, or nested immutable data classes).
Kotlin shared domain models intended for Swift cross-boundary dispatch MUST be deeply immutable (consisting solely of primitive types, immutable strings, or nested immutable data classes).
Teams MUST use SKIE or explicit Swift concurrency wrappers to convert Kotlin `StateFlow` and `SharedFlow` into `AsyncSequence` conforming to Swift 6 Sendable requirements.
Teams MUST use SKIE or explicit Swift concurrency wrappers to convert Kotlin `StateFlow` and `SharedFlow` into `AsyncSequence` conforming to Swift 6 Sendable requirements.
Components NEVER bridge Kotlin mutable collections (`MutableList`, `MutableMap`, `MutableSet`) to Swift
Components NEVER bridge Kotlin mutable collections (`MutableList`, `MutableMap`, `MutableSet`) to Swift; collections must be exported as immutable collections and copied to Swift native value types (`Array`, `Dictionary`, `Set`) at the boundary.
Engineers MUST NOT apply `@unchecked Sendable` to Kotlin Objective-C bridged classes unless the Kotlin class is provably immutable, thread-confined, or internally synchronized with cross-platform primitives.
Engineers MUST NOT apply `@unchecked Sendable` to Kotlin Objective-C bridged classes unless the Kotlin class is provably immutable, thread-confined, or internally synchronized with cross-platform primitives.
Frequently Asked Technical Questions
Common questions developers face when configuring AI coding assistants for this stack:
Q:Why is KMP 2.1 and Swift 6 Strict Concurrency Isolation and Sendable Interop Boundary critical for AI coding assistants?
Enforces complete data race safety across the Kotlin Multiplatform 2.1 and Swift 6 language boundary by isolating Objective-C export interfaces within strict Swift actors. Prevents passing non-Sendable Kotlin reference types across asynchronous boundaries and mandates thread-safe Sendable DTO contracts or SKIE-generated Swift concurrency wrappers for all exported Coroutine flows and suspend functions. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.
Q:How does adopting this rule prevent AI hallucinations?
This rule explicitly declares what the AI must avoid (Passing Non-Sendable Kotlin Reference Types and Unisolated Completion Handlers Across Swift 6 Actor Boundaries) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.
Q:Which AI coding environments are supported?
This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).
Q:Can I combine this rule with other technology stacks?
Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.