I was wondering if there was a way to alleviate th...
# kotlin-native
y
I was wondering if there was a way to alleviate this problem I’m having with kotlin/swift interoperability. I have a generic interface in Kotlin
Copy code
interface Repository<T> {
    fun add(model: T): Boolean
}
I have another interface that conforms to `Repository`:
Copy code
interface TestModelRepository : Repository<TestModel> {
      override fun add(model: TestModel): Boolean
   }
When I have a class in Swift that conforms to
TestModelRepository
class SwiftTestModelRepository: TestModelRepository
it wants me to implement both
add
methods. One with type
id
and one with type
TestModel
. I only want to implement one of them. Is there a workaround for this where I only implement the overridden one from
TestModelRespository
and not from the generic Repository? As a backup I can only declare
add
in
TestModelRepository
and remove it from
Repository
but this will make the code less clean as I want to have many more repositories that conform to
Repository
and would like to reuse the
add
method.
s
Thank you for providing this case. Unfortunately, Swift seems to imply restrictions that are stricter than expected: Swift compiler doesn’t consider these two methods with same Objective-C selector as the same method. As a workaround, you can stop using generics here.
y
Ah okay, thanks
s
Also this Kotlin interface can be implemented in Objective-C.