Я пытаюсь написать короткий и расширяемый метод для запроса данных с сервера.
Этот код не скомпилирован:
func getData<DataType>(url: String, completion : @escaping ((DataType) -> ())) where DataType: Array<Codable>? {
//
}
Ошибка: Type 'DataType' constrained to non-protocol, non-class type 'Array<Codable>?' (aka 'Array<Decodable & Encodable>')
Плохой обходной путь, который я смог найти:
func getData<RecordType>(url: String, completion : @escaping ((Array<RecordType>?, RecordType) -> ())) where RecordType: Codable {
//
}