Let's create the LocationDataManager
file:
- Right-click on the
Model
folder in theLocation
folder and selectNew File
. - In
Choose a template for your new file
, selectiOS
at the top and thenSwift File
. Then hitNext
. - Name this file
LocationDataManager
, and then hitCreate
. - We need to define our class definition now, so add the following under the
import
statement:
class LocationDataManager { }
- Inside the class declaration, add the following variable to keep our array private, as there is no reason to have to access this outside the class:
private var locations:[String] = []
- Now, let's add the following methods after our variable:
init() { fetch() } func fetch() { for location in loadData() { if let city = location["city"] as? String, let state = location["state"] as? String { locations.append("\(city), \(state)") } } } func numberOfItems() -> Int { return locations.count } func locationItem(at index...