https://kotlinlang.org logo
#kotlin-native
Title
# kotlin-native
t

Trey

03/21/2024, 8:51 PM
I'm trying to implement
PTChannelManagerDelegateProtocol
in iosMain and I'm getting
"Conflicting overloads"
exceptions. The confusing part to me is that the methods all have unique parameter names. Here is an example of two methods:
Copy code
public open fun channelManager(channelManager: PTChannelManager, didActivateAudioSession: AVAudioSession): 
public open fun channelManager(channelManager: PTChannelManager, didDeactivateAudioSession: AVAudioSession):
How do I resolve these errors?
l

Landry Norris

03/21/2024, 9:57 PM
You can use the name of the parameter to distinguish https://kotlinlang.org/docs/native-objc-interop.html#method-names-translation
t

Trey

03/21/2024, 9:59 PM
It's not compiling though. That is the issue.
Screenshot 2024-03-21 at 6.00.19 PM.png
Copy code
class PushToTalkManager(
): NSObject(), PTChannelManagerDelegateProtocol, PTChannelRestorationDelegateProtocol {
}
This is how I'm trying to use it.
l

Landry Norris

03/21/2024, 10:02 PM
I see. You're overriding, not calling. I remember running into this before and fixing it, but don't remember off hand how I resolved this.
👍 1
The worst-case solution I can think of is to use a cinterop def file to create an abstract class in Obj-C that implements this, and provides methods with different names, then extend that in Kotlin, but that's obviously not a good experience.
Can you just suppress the error? I think some of these K/N oddities are suppressable.
t

Trey

03/21/2024, 10:07 PM
Android Studio isn't suggesting any way to suppress. I'll dig through the docs some more.
d

Deepak Nulu

03/21/2024, 10:09 PM
Parameter names are not important in the signature of a method. The signature consist only of the function name and the ordered parameter types. So in your case, both functions have the same name and the same ordered parameter types. So having different parameter names does not help
l

Landry Norris

03/21/2024, 10:09 PM
@Suppress("CONFLICTING_OVERLOADS")
t

Trey

03/21/2024, 10:10 PM
That suppresses the error. 🙂
l

Landry Norris

03/21/2024, 10:11 PM
The methods come from an Obj-C interface, where unfortunately, the name of a parameter is part of the method's signature.
t

Trey

03/21/2024, 10:11 PM
I'll clean this up and hopefully it will build. Thanks for the help!
d

Deepak Nulu

03/21/2024, 10:12 PM
@Landry Norris ah, ok.
l

Landry Norris

03/21/2024, 10:13 PM
I could have sworn there was an annotation that told the compiler about this condition, but I may just be thinking of the suppress.
👍 1