Skip to content

Instantly share code, notes, and snippets.

@thanakijwanavit
Created January 9, 2022 05:49
Show Gist options
  • Save thanakijwanavit/1e3f8df2f6f8142a3b00b01bd26ddf81 to your computer and use it in GitHub Desktop.
Save thanakijwanavit/1e3f8df2f6f8142a3b00b01bd26ddf81 to your computer and use it in GitHub Desktop.
decoding pandas generated csv in swift
import CodableCSV
extension VillaMarket{
static func getOnlineCsv()async throws ->[Item]{
let url = URL(string: "https://url/item.csv")!
let (data, _) = try await URLSession.shared.data(from: url)
let decoder = CSVDecoder{
$0.bufferingStrategy = .sequential
$0.headerStrategy = .firstLine
}
let items = try decoder.decode([Item].self, from: data)
return items
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment