https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
m

Mathis [Off The Grid]

11/08/2023, 4:13 PM
I'm trying to implement a Bluetooth solution using platform specific logic. When creating a
centralManagerDelegate = object : NSObject(), CBCentralManagerDelegateProtocol
, I'm trying to implement some of its functions. However, because they all have the same function name and only vary in the parameter types, and names, I have two functions which have exactly the same parameter types required and this creates a conflicting overload. The two conflicting functions are defined below :
override fun centralManager(central: CBCentralManager, didDisconnectPeripheral: CBPeripheral, error: NSError?) {
}
override fun centralManager(central: CBCentralManager, didFailToConnectPeripheral: CBPeripheral, error: NSError?) {
}
I have tried renaming the functions but it doesn't work with overriding, and annotations such as
@ObjCName("centralManagerDidDisconnectPeripheral:error:")
don't seem to work for overriding functions. Has anyone encountered a similar issue? I am using Kotlin Multiplatform plugin version 0.6.1 and Kotlin version 1.9.0
s

Sebastian Sellmair [JB]

11/13/2023, 2:08 PM
See this example: https://github.com/sellmair/pacemaker/blob/master/bluetooth-core/src/appleMain/kotlin/io/sellmair/pacemaker/ble/AppleCentralManagerDelegate.kt You are required to
@Suppress("CONFLICTING_OVERLOADS", "PARAMETER_NAME_CHANGED_ON_OVERRIDE")
cc @etolstoy
8 Views