Question regarding Value: Decodable and Closures
fredagsfys opened this issue · 0 comments
fredagsfys commented
Hey there, I'm new to iOS development in general but especially Combine/SwiftUI.
I've followed your clean architecture and tried to extend it a bit by introducing credentials manager and injecting a token in the WebRepository call.
However, what puzzles me is that if I wrap following code below into a closure I get Generic parameter 'Value' could not be inferred.
session
.dataTaskPublisher(for: request)
.requestJSON(httpCodes: httpCodes)
Could you please advise on how to get this solved? This is the whole picture of the function.
func call<Value>(endpoint: APICall, httpCodes: HTTPCodes = .success) -> AnyPublisher<Value, Error>
where Value: Decodable
{
do {
var request = try endpoint.urlRequest(baseURL: baseURL)
credentialsManager.credentials()
.map { (credentials: Credentials) in
let token = credentials.accessToken
request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
}
.map { (_ publisher: AnyPublisher<Value, Error>) in
session
.dataTaskPublisher(for: request) // Generic parameter 'Value' could not be inferred
.requestJSON(httpCodes: httpCodes)
}
} catch {
return Fail<Value, Error>(error: error).eraseToAnyPublisher()
}
}