### Kotlin Global Functions and Properties with SKIE Source: https://skie.touchlab.co/intro/features SKIE simplifies calling Kotlin global functions and properties from Swift by generating wrappers. This removes the need to use the file-based namespace (e.g., `FileKt`) and allows for direct, cleaner calls. ```kotlin fun globalFunction(i: Int): Int = i ``` ```swift globalFunction(i: 1) ``` -------------------------------- ### Kotlin Interface Extension Call in Swift Source: https://skie.touchlab.co/intro/features Demonstrates how SKIE allows calling Kotlin interface extensions from Swift using a more natural Swift syntax, similar to class extensions. Without SKIE, Kotlin's top-level extension functions require a different calling convention. ```Kotlin interface I class C : I fun I.interfaceExtension(i: Int): Int = i ``` ```Swift FileKt.interfaceExtension(C(), i: 1) ``` ```Swift C().interfaceExtension(i: 1) ``` -------------------------------- ### Convert Kotlin StateFlow to Swift AsyncSequence with SKIE Source: https://skie.touchlab.co/intro/features Demonstrates how SKIE automatically converts a Kotlin `StateFlow>` into a Swift `AsyncSequence` with a `[String]` type argument. This eliminates the need for manual type casting and ensures type argument preservation. The converted Flow integrates with Swift's concurrency lifecycle, supporting two-way cancellation. ```kotlin class ChatRoom { private val _messages = MutableStateFlow(emptyList()) val messages: StateFlow> = _messages // etc } ``` ```swift class ChatRoomViewModel: ObservableObject { let chatRoom = ChatRoom() @Published private(set) var messages: [String] = [] @MainActor func activate() async { for await messages in chatRoom.messages { // No type cast (eg `it as! [String]`) is needed because the generic type is preserved. self.messages = messages } } } ``` ```swift VStack { // SwiftUI views .. } .task { await viewModel.activate() } ``` -------------------------------- ### Kotlin Overloaded Functions Call in Swift Source: https://skie.touchlab.co/intro/features Illustrates how SKIE handles Kotlin overloaded functions when called from Swift. SKIE preserves the original function names, avoiding the need for Swift to use disambiguation suffixes like `_` for overloaded functions that have different parameter types. ```Kotlin fun foo(i: Int) { } fun foo(i: String) { } ``` ```Swift foo(i: 1) foo(i_: "A") ``` ```Swift foo(i: 1) foo(i: "A") ``` -------------------------------- ### Kotlin Suspend Function Call in Swift with SKIE Source: https://skie.touchlab.co/intro/features Shows how SKIE enables Kotlin suspend functions to be called from Swift using native Swift `async/await` syntax. This provides proper support for cancellation and allows calling from background threads, bridging Kotlin's coroutine context with Swift's concurrency model. ```Kotlin class ChatRoom { suspend fun send(message: String) { // Send a message } } ``` ```Swift let chatRoom = ChatRoom() let task = Task.detached { // Runs on a background thread try? await chatRoom.send(message: "some message") } // Cancellation of the task also cancels the Kotlin coroutine task.cancel() ``` -------------------------------- ### Kotlin Default Function Arguments with SKIE Source: https://skie.touchlab.co/intro/features SKIE restores default argument support for Kotlin functions in Swift by generating overloads for all default argument combinations. This improves the developer experience by allowing more natural function calls. ```kotlin fun sayHello(message: String = "Hello") { println(message) } ``` ```swift // calls sayHello(message: "Hello") sayHello() ``` -------------------------------- ### Kotlin Enum to Swift Enum Conversion with SKIE Source: https://skie.touchlab.co/intro/features SKIE automatically generates Swift enums from Kotlin enums, enabling exhaustive switching in Swift without the need for default cases. This simplifies code and improves type safety. ```kotlin enum class Turn { Left, Right } ``` ```swift func changeDirection(turn: Turn) { switch turn { case .left: goLeft() case .right: goRight() } } ``` -------------------------------- ### Kotlin Sealed Class to Swift Enum Wrapping with SKIE Source: https://skie.touchlab.co/intro/features SKIE wraps Kotlin sealed classes into Swift enums, allowing for exhaustive switching in Swift. It generates a helper function `onEnum(of:)` to conveniently convert Kotlin sealed class instances to their Swift enum counterparts. ```kotlin sealed class Status { object Loading : Status() data class Error(val message: String) : Status() data class Success(val result: SomeData) : Status() } ``` ```swift func updateStatus(status: Status) { switch onEnum(of: status) { case .loading: showLoading() case .error(let data): showError(message: data.message) case .success(let data): showResult(data: data.result) } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.