Guy, someone has a tip about how to find a Kotlin ...
# multiplatform
t
Guy, someone has a tip about how to find a Kotlin
object
instance on Swift side been
null
? I have a code that on the second time I open the iOS app an object is null. KMP code:
Copy code
// commonMain
public object MultiplatformFeature {
    // ...
}

// iosMain
@ShouldRefineInSwift
public fun MultiplatformFeature.plugin(objCClass: ObjCClass): Any? {
    // ...
}
Swift refined code. Yes, I know that ShouldRefineInSwift is experimental but it's working well.
Copy code
extension MultiplatformFeature {
    public static func plugin<T: FeaturePlugin>(_ type: AnyClass) -> T? {
        let osLogger = Logger()
        osLogger.debug(">>>> shared 1: \(shared)")
        osLogger.debug(">>>> shared 2: \(MultiplatformFeature.shared)")

        let instance = shared.__pluginObjCClass(type)

        if let clazz = instance as? T {
            return clazz
        } else {
            return nil
        }
    }
}
iOS app is opening and running well. But after close and finish the app and open it again the
shared
has null pointer. Logs and LLDB print the
shared
having a value but the app crashes with null pointer and XCode debugger shows a null reference. Screenshot below.