Hello, when I use native library for iOS in KMM, I...
# multiplatform
c
Hello, when I use native library for iOS in KMM, I used cinterop to generate kotlin binding codes. But for delegation that is implemented by Objective-C is converted to Kotlin interface based on NSObjectProtocol type. But when I try to implement this interface on KMM iOS code, it requires to implement many unnecessary functions like hash, equal, etc. But the problem is that even when I override all the functions, I still see the following issue.
Internal error occurred while analyzing this expression: InvalidCardinalityException: Container: LocalClassifierAnalyzer: Request interface org.jetbrains.kotlin.builtins.PlatformSpecificCastChecker cannot be satisfied because there is more than one type registered Clashed registrations: Instance: NativePlatformSpecificCastChecker, Instance: NativePlatformSpecificCastChecker, Instance: NativePlatformSpecificCastChecker
This is exmaple delegate definition in Objective-C header file @protocol TestDelegate NSObject @required - (void) onTest:(Test *)testObj scanData:(NSString *)scanData; @end And converted Kotlin binding code is like this
@kotlinx.cinterop.ExperimentalForeignApi public expect interface TestDelegateProtocol : platform.darwin.NSObjectProtocol {
@kotlin.commonizer.ObjCCallable public abstract expect fun onTest(testObj: com.example.proj.Test?, scanData: kotlin.String?): kotlin.Unit }
m
I think you probably want to inherit from NSObject for the class that is implementing the protocol.
c
But it’s generated by cinterop
Do you have any idea of inherift from NSObject?
m
Copy code
class MyTestDelegate : NSObject(), TestDelegateProtocol {}
c
Wow, thanks. Build is okay, Let me check feature.