I was trying to write an extension in Swift on a g...
# kotlin-native
h
I was trying to write an extension in Swift on a generic Kotlin type (to add Swift Combine support to SqlDelight's
Query<RowType>
). @russhwolf suggested using a top level func like
func createPublisher<T>(query: RuntimeQuery<T>) -> AnyPublisher<RuntimeQuery<T>, Never>
. That works! Are there maybe any other solutions?
My code that doesn't compile:
Copy code
extension RuntimeQuery {
  func asPublisher() -> AnyPublisher<RuntimeQuery<RowType>, Never> {
    // ...
  }
}
// Fails with: 'Extension of a generic Objective-C class cannot access the class's generic parameters at runtime.'
@saket pointed me to this from Badoo's Reaktive: https://github.com/badoo/Reaktive/pull/393
r
Yeah I originally dug into this in the context of converting between coroutines/flow and RxSwift. The solution there required wrappers similar to what Reaktive uses to get the generic exposed to Swift, and then top-level functions in Swift to have generic transformers to RxSwift types.
h
That probably entails one wrapper per concrete type, right? Was hoping to avoid that, but for my tiny side project it should be okay.