Is there a working example of iOS app with full ko...
# ios
a
Is there a working example of iOS app with full kotlin, even the main ?
f
I don’t think it’s a good idea, SwiftUI/UIKit and Kotlin can’t really work together. it’s why compose multiplaftorm has been made
a
I'm working with low level rendering API, so I dont really care about SwiftUI. Compose is quite heavy to use, I'm more looking to a way with no framework at all.
f
Xcode can’t compile Kotlin directly, you can have a minimal entry point in swift then using Kotlin (as a library) all you want
a
Already have one
Copy code
@file:OptIn(ExperimentalForeignApi::class, BetaInteropApi::class, ExperimentalObjCName::class)

import kotlinx.cinterop.BetaInteropApi
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.autoreleasepool
import kotlinx.cinterop.memScoped
import kotlinx.cinterop.toCStringArray
import platform.Foundation.NSStringFromClass
import platform.UIKit.UIApplication
import platform.UIKit.UIApplicationDelegateProtocol
import platform.UIKit.UIApplicationDelegateProtocolMeta
import platform.UIKit.UIApplicationMain
import platform.UIKit.UIResponder
import platform.UIKit.UIResponderMeta
import platform.UIKit.UIScreen
import platform.UIKit.UIViewController
import platform.UIKit.UIWindow
import platform.darwin.dispatch_async
import platform.darwin.dispatch_get_main_queue
import kotlin.experimental.ExperimentalObjCName

fun main(args: Array<String>) {
    println("Hello cube")
    memScoped {
        val argc = args.size + 1
        val argv = (arrayOf("konan") + args).toCStringArray(memScope)
        autoreleasepool {
            println("Hello cube ${args.joinToString()}}")
            UIApplicationMain(argc, argv, null, NSStringFromClass(AppDelegate))
        }
    }
}

class AppDelegate : UIResponder, UIApplicationDelegateProtocol {
    companion object : UIResponderMeta(), UIApplicationDelegateProtocolMeta {}

    private var _window: UIWindow? = null

    @OverrideInit
    constructor() : super()

    override fun application(
        application: UIApplication,
        didFinishLaunchingWithOptions: Map<Any?, *>?
    ): Boolean {
        println("Hello cube")
        val window = UIWindow(frame = UIScreen.mainScreen.bounds)
        setWindow(window)


        return true
    }

    override fun window() = _window

    override fun setWindow(window: UIWindow?) {
        _window = window
    }
}
But that crashing when running on simulator with no explicit error. That why I looking to a project that work to understand what is wrong. I'm rolling back to XCFramework with a few piece of swift code and a XCode project, but that a shame to not provide a full iOS experience directly with gradle.
f
you like to experiment it’s fine 😄 , good luck
did you try https://touchlab.co/xcodekotlin for your crash issues?
a
I will give a try, thanks