Configuring MapDataManager to use RestaurantDataManager

Currently, the Map screen only shows sample data from the MapLocations.plist file. You will now update MapDataManager to use RestaurantDataManager. Click MapDataManager.swift (inside the Model folder in the Map folder) in the Project navigator and update the fetch() method as follows:

func fetch(completion:(_ annotations:[RestaurantItem]) -> ()){
let manager = RestaurantDataManager()
manager.fetch(by: "Boston", completionHandler: { (items) in
self.items = items
completion(items)
})
}

Let's break this down:

  • func fetch(completion:(_ annotations:[RestaurantItem]) -> ())
    A completion handler is used to assign the result of this method to the annotations property when it has finished execution.
  • let manager = RestaurantDataManager()
    This creates an instance of RestaurantDataManager
  • manager.fetch(by: "Boston", completionHandler: { (items) in self.items = items
    completion(items)
    This calls
     the fetch() method of RestaurantDataManager to get a list of restaurants from Boston.json. This is hardcoded for now as the iOS Simulator does not have a functional GPS:
To see restaurants at a different location, change the name of the JSON file used.

If you run your app now and select the Map screen, you should see pins for restaurants in Boston.

You are now done with the Map screen, but before you can display data in the Restaurant List screen, there is a possibility to consider. The user's choices for location and cuisine may not return any results, so you will implement a screen that informs the user when there is no data to be displayed in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.230.82