-
-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
Issue
I have a function with the following Swift code:
let urlRequest = try self.urlRequest(.get, request: .products, .count, for: .core)
let (data, urlResponse) = try await session.data(for: urlRequest)
return try APIManagerDecoder.decode(Int.self, from: data)This gets transpiled to the following Kotlin code:
val urlRequest = this.urlRequest(ProjectAPI.Method.get, ProjectAPI.Endpoint.products, ProjectAPI.Endpoint.count, for_ = APIManager.TokenOwner.core)
val (data, urlResponse) = session.data(for_ = urlRequest)
return@l APIManagerDecoder.decode(Int::class, from = data)I'm getting an error from the compiler that refers to the following line:
return@l APIManagerDecoder.decode(Int::class, from = data)
Argument type mismatch: actual type is 'KClass', but 'KClass<uninferred T (of fun decode)>' was expected.
Valid workaround:
I was able to find a workaround as follows:
let urlRequest = try self.urlRequest(.get, request: .products, .count, for: .core)
let (data, urlResponse) = try await session.data(for: urlRequest)
return try APIManagerDecoder.decode(IntWrapper.self, from: data).valueWhere this is the 'IntWrapper' struct:
struct IntWrapper: Decodable {
var value: Int
init(_ value: Int) {
self.value = value
}
init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
self.value = try container.decode(Int.self)
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels