In some Kotlin Native code I'm implementing some m...
# kotlin-native
s
In some Kotlin Native code I'm implementing some methods defined in an ObjC protocol. A problem I'm having is that that two of the methods basically have the same signature but different parameters names. I need to implement both as they'll be called by the ObjC code at different times for different events. When I try to do this the compiler complains about conflicting overloads. Is there a way around this? For reference the protocol is defined in CoreBluetooth's
CBCentralManagerDelegate
https://developer.apple.com/documentation/corebluetooth/cbcentralmanagerdelegate. The conflicting methods are
didDisconnect
and
didFailToConnect
.
o
see https://github.com/JetBrains/kotlin-native/blob/master/OBJC_INTEROP.md#method-names-translation:
Copy code
Generally Swift argument labels and Objective-C selector pieces are mapped to Kotlin
parameter names. Anyway these two concepts have different semantics, so sometimes
Swift/Objective-C methods can be imported with a clashing Kotlin signature. In this case
the clashing methods can be called from Kotlin using named arguments, e.g.:

[player moveTo:LEFT byMeters:17]
[player moveTo:UP byInches:42]

in Kotlin it would be:

player.moveTo(LEFT, byMeters = 17)
player.moveTo(UP, byInches = 42)
thus you could try to suppress conflicting overloads warning with
Suppress("CONFLICTING_OVERLOADS")
and see it it will work
if not - please report an issue to the tracker
s
I'll give that a try thanks.
d
@Sam I ran into the same issue and the above solution worked for me. One other thing to keep in mind is that In Objc-C/Swift, the return type is part of the method signature, where as in Kotlin it is not. A good example of this is If you are conforming to UITableViewDataSourceProtocol and/or UITableViewDelegateProtocol, you will also see this issue arise.
🙏 2