https://kotlinlang.org logo
Title
j

jessewilson

05/10/2023, 2:48 AM
I’d like to implement
UITableViewDataSourceProtocol
in pure Kotlin (1.8.20 !), and I’m running into problems with Objective-C conflicting overloads. My code looks like this:
private val tableViewDataSource: UITableViewDataSourceProtocol =
    object : NSObject(), UITableViewDataSourceProtocol {
      override fun numberOfSectionsInTableView(
        tableView: UITableView,
      ): NSInteger = ...

      override fun tableView(
        tableView: UITableView,
        numberOfRowsInSection: NSInteger,
      ): NSInteger = ...

      override fun tableView(
        tableView: UITableView,
        cellForRowAtIndexPath: NSIndexPath,
      ): UITableViewCell = ...
    }
Which triggers a failure in the
compileCommonMainKotlinMetadata
task:
> Task :redwood-treehouse-lazylayout-uiview:compileCommonMainKotlinMetadata FAILED

e: file:///Volumes/Development/redwood/redwood-treehouse-lazylayout-uiview/src/commonMain/kotlin/app/cash/redwood/treehouse/lazylayout/uiview/UIViewLazyList.kt:93:10 

Return type of 'tableView' is not a subtype of the return type of the overridden member
  'public open expect fun tableView(tableView: UITableView, canMoveRowAtIndexPath: NSIndexPath): Boolean 
defined in platform.UIKit.UITableViewDataSourceProtocol'
A similar issue has come up before here. I don’t think compiling Kotlin metadata was necessary in 2018. Any recommendations on how to work-around or fix this? I’m currently disabling the task in Gradle and that feels bad.
tasks.configureEach { task ->
  if (task.name == "compileCommonMainKotlinMetadata") {
    task.onlyIf { false }
  }
}
r

ribesg

05/10/2023, 8:05 AM
You can suppress these errors. I suppress them at the file level to not pollute code:
@file:Suppress(
    "PARAMETER_NAME_CHANGED_ON_OVERRIDE",
    "RETURN_TYPE_MISMATCH_ON_OVERRIDE"
)
l

louiscad

05/26/2023, 12:51 AM
I fear suppression of errors will go away in future Kotlin versions. I'd submit an issue about that specific problem on kotl.in/issue