Created
January 20, 2020 04:45
-
-
Save garethpaul/88392405e1be36d0819be1d7763d3809 to your computer and use it in GitHub Desktop.
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
| // | |
| // VenueFetcher.swift | |
| // FSQNearby | |
| // | |
| // Created by GPJ on 1/19/20. | |
| // Copyright © 2020 GPJ. All rights reserved. | |
| // | |
| import Foundation | |
| public class VenueFetcher: ObservableObject { | |
| @Published var venues = [Venue]() | |
| init() { | |
| load() | |
| } | |
| private func load() { | |
| let url = URL(string: "FOURSQUARE_VENUE_SEARCH_API")! | |
| URLSession.shared.dataTask(with: url) {(data,response,error) in | |
| do { | |
| if let d = data { | |
| let foursquareSearch = try JSONDecoder().decode(FoursquareSearch.self, from: d) | |
| DispatchQueue.main.async { | |
| let responseData = foursquareSearch.response | |
| self.venues = (responseData?.venues)! | |
| print(self.venues) | |
| } | |
| } else { | |
| print("No Data") | |
| } | |
| } catch { | |
| print(error) | |
| print ("Error: " + error.localizedDescription) | |
| } | |
| }.resume() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment