Created
January 9, 2022 05:49
-
-
Save thanakijwanavit/1e3f8df2f6f8142a3b00b01bd26ddf81 to your computer and use it in GitHub Desktop.
decoding pandas generated csv in swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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