I need to use .publishDecodable together with Result, I followed the instructions, but I ran into this error: "generic parameter 't' could not be inferred closure"
@Published var loginModel: [LoginModel] = [LoginModel]()
var cancellation: AnyCancellable?
func request<T: Codable>(_ url: String, method: HTTPMethod = .get, headers: HTTPHeaders? = nil, parameters: Codable? = nil) -> AnyPublisher<Result<T, AFError>, Never> {
let publisher = AF.request(url, method: method, headers: headers)
.validate()
.publishDecodable(type: T.self)
return publisher.result()
}
func login(email: String, password: String) {
let parameters = LoginParameters(
email: email,
password: password
)
cancellation = request(serverURL + "login", method: .post, parameters: parameters)
.sink { [self] response in
switch response {
case .success:
loginModel = response.value()
case .failure(error):
print(error)
}
}
}
