Skip to content

Instantly share code, notes, and snippets.

@gtokman
Last active September 24, 2021 01:32
Show Gist options
  • Save gtokman/1d5bff38b7bd67b06504aa790cc6e322 to your computer and use it in GitHub Desktop.
Save gtokman/1d5bff38b7bd67b06504aa790cc6e322 to your computer and use it in GitHub Desktop.
@State var businesses = [Bussiness]()
NavigationView {
List {
ForEach(businesses) { business in
Text(business.name ?? "no name")
}
}
.listStyle(.plain)
.navigationTitle(Text("Boston"))
// Run async code straight from the view
.task {
do {
let (data, _) = try await session.data(for: request)
let result = try JSONDecoder().decode(SearchResult.self, from: data)
self.businesses = result.businesses
} catch {
print(error.localizedDescription)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment