Я пытаюсь повторно использовать код здесь, но у компилятора его не будет. MyModel реализует Decodable.
func removeApplicationRequestOperation(request: Request, completion: @escaping (Result<MyModel, Error>) -> Void) -> RequestOperation {
return newRequestOperation(for: request, modelType: MyModel.self, completion: completion) // <-- Won't compile!
}
private func newRequestOperation<T: Decodable>(for request: Request?, modelType: T.Type, completion: @escaping (Result<T.Type, Error>) -> Void) -> RequestOperation {
return requestOperation(request: request) { operation in
do {
guard let response = operation.response, response.successful,
let rawData = response.rawData,
let model = try JSONDecoder().decode(modelType, from: rawData) as? T.Type else {
completion(.failure(.parsingError))
return
}
completion(.success(model))
} catch {
completion(.failure(.parsingError))
}
}
}
Ошибка: Cannot convert value of type '(Result<MyModel, Error>) -> Void' to expected argument type '(Result<_.Type, Error>) -> Void'