Did anyone manage to define AppDelegate class directly in iosMain kotlin source set? I tried a couple of different things and couldn’t make it work. My latest code is in the thread 🧵.
Blaž Vantur
10/23/2024, 12:00 PM
My custom AppDelegate class
`InspektifyAppDelegate.kt`:
Copy code
class InspektifyAppDelegate: NSObject(), UIApplicationDelegateProtocol {
}
Usage of it in swift code
`iOSApp.swift`:
Copy code
import SwiftUI
import ComposeApp
@main
struct iOSApp: App {
@UIApplicationDelegateAdaptor(InspektifyAppDelegate.self) var appDelegate
init() {
KoinImplKt.doInitKoin()
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
Error that I am getting when trying to run iOS app:
Copy code
error: generic struct 'UIApplicationDelegateAdaptor' requires that 'InspektifyAppDelegate' conform to 'UIApplicationDelegate'
@UIApplicationDelegateAdaptor(InspektifyAppDelegate.self) var appDelegate
^
SwiftUI.UIApplicationDelegateAdaptor:4:43: note: where 'DelegateType' = 'InspektifyAppDelegate'
@MainActor @propertyWrapper public struct UIApplicationDelegateAdaptor<DelegateType> : DynamicProperty where DelegateType : NSObject, DelegateType : UIApplicationDelegate {
f
François
10/23/2024, 12:45 PM
*__attribute__*((unavailable("Kotlin subclass of Objective-C class can't be imported")))
I found this answer on stackoverflow:
https://stackoverflow.com/a/69281270
Will try to replicate it for that custom view and then used it with AppDelegate.