I would like to make a helper function which takes input of encodable/decodable type in order to encode or decode json. I have tried
static func loadCache<T:Decodable>(fileName:String, type:T)throws->T{
let data = try FileManager.loadCache(fileName: fileName)
return try JSONDecoder().decode(T.self, from: data)
}
Using the function
let products = try loadCache(fileName: Product.cacheFileName(), type: [Product])
I am getting error Type '[Product].Type' cannot conform to 'Decodable'
what is the correct way to pass this to a function Thanks