Skip to content

Instantly share code, notes, and snippets.

@KrauserHuang
Created May 9, 2021 06:45
Show Gist options
  • Save KrauserHuang/bd757d2eacf563ba9210dcec2cad3cd3 to your computer and use it in GitHub Desktop.
Save KrauserHuang/bd757d2eacf563ba9210dcec2cad3cd3 to your computer and use it in GitHub Desktop.
// fetch google sheet all datas and store in menus
func fetchItem() {
// remember to switch googlesheetid with your own one!
let urlStr = "https://spreadsheets.google.com/feeds/list/googlesheetid/od6/public/values?alt=json"
if let url = URL(string: urlStr) {
URLSession.shared.dataTask(with: url) { (data, response, error) in
if let data = data {
let decoder = JSONDecoder()
do {
let searchResponse = try decoder.decode(Menu.self, from: data)
DispatchQueue.main.async {
self.menus = searchResponse.feed.entry
self.tableView.reloadData()
}
} catch {
print(error)
}
}
}.resume()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment