I am trying to use generics in swift to intrepret http response. All The Json responses have the same signature at the top :
{
"request": "foo",
"result": "[{},{}....]
}
So I am using this :
public struct HttpResponse<DATA: Codable> {
public let request: Bool?
public let result: DATA?
enum CodingKeys: String, CodingKey {
case request= "request"
case result = "result"
} ..
In My Network layer:
final class Network<T: Decodable> {
func getItems(_ path: String) -> Observable<HttpResponse<[T]>> {
let absolutePath = "\(endPoint)/\(path)"
return RxAlamofire
.data(.get, absolutePath)
.debug()
.observeOn(scheduler)
.map({ data -> [T] in
return try JSONDecoder().decode([T].self, from: data)
})
}
I get this error in Observable<PlutusResponse<[T]>>
Generics Type 'T' does not conform to protocol 'Encodable'
How to correctly use this?