Refactoring MapDataManager

MapDataManager already has a loadData() method, which is hardcoded to read Maplocations.plist. Now that you have created the DataManager protocol, you will modify MapDataManager to use it instead. Perform the following steps:

  1. With MapDataManager selected in the Project navigator, find and delete the loadData() method. You'll see an error because the fetch() method calls the loadData() function, which you just removed. You'll fix this shortly.
  2. Add the DataManager protocol to the class declaration as follows:
class MapDataManager: DataManager

This makes the load(file:) method available to MapDataManager.

  1. Modify the for data in loadData() line in the fetch() method as follows to fix the error:
for data in load(file: "MapLocations")

Your updated MapDataManager class should look like the following:

import Foundation

class MapDataManager: DataManager {

fileprivate var items:[RestaurantItem] = []

var annotations:[RestaurantItem] {
return items
}

func fetch(completion:(_ annotations:[RestaurantItem]) -> ()){
if items.count > 0 { items.removeAll() }
for data in load(file: "MapLocations") {
items.append(RestaurantItem(dict: data))
}
completion(items)
}
}

The error should be gone. Now, you will refactor ExploreDataManager as well to make it adopt the DataManager protocol 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.146.34.146