Repository navigation
Can I use SwiftUI? #62
Replies: 1 comment
|
The plugin cannot expose SwiftUI's view-building API directly to Kotlin: its interop boundary is Objective-C, while SwiftUI views are Swift structs and generic types. You can keep a SwiftUI screen in Swift and expose an Objective-C-compatible factory returning import Foundation
import SwiftUI
import UIKit
@objc public final class SwiftScreenFactory: NSObject {
@MainActor
@objc public static func makeGreeting(_ title: String) -> UIViewController {
UIHostingController(rootView: Text(title))
}
}Put that Swift file in the source directory configured for swiftklib. Kotlin then calls the generated factory from This gives Kotlin a usable screen boundary, but the SwiftUI layout itself remains Swift code; swiftklib does not supply a Kotlin version of the SwiftUI DSL. Sources: the plugin's Objective-C compatibility requirement, Kotlin's Swift import limitations, and Apple's UIHostingController. |
Uh oh!
There was an error while loading. Please reload this page.
This is probably a silly question, but can I use this to create Kotlin bindings for SwiftUI? E.g. can I build a SwiftUI interface in Kotlin code?
All reactions