I wish to add a generic merchandise in an array. How do I obtain it in following technique:
func get<T: Decodable>(from url : URL, sort: T.Sort, completion : @escaping (Consequence<T, ApiError>) -> ()) {
// messages.append((url, completion))
}
var messages : [(url: URL, completion: (Result<Codable, Error>) -> ())] = []
I get following error when I attempt to append:
Can’t convert worth of sort ‘(URL, (Consequence<T, ApiError>) -> ())’ to
anticipated argument sort ‘(url: URL, completion: (Consequence<any Decodable,
ApiError>) -> ())’
I’m utilizing get operate to return api response as a generic mannequin and attempting to make use of above code in my check instances.
I consider I must specify that array is anticipating a generic merchandise however I’m not certain easy methods to obtain it.
Edit:
authentic operate for which I’m writing tes case:
public func getTimeTable() -> AnyPublisher<TimetableModel, Error> {
Future { [weak self] promise in
guard let self = self else { return }
httpClient.get(from: url, sort: TimetableModel.self) { lead to
change consequence {
case .success(let timeTable):
promise(.success(timeTable))
case .failure(let error):
promise(.failure(error))
}
}
}.eraseToAnyPublisher()
}