Let's create the LocationDataManager file:
- Right-click on the Model folder in the Location folder and select New File.
- Under Choose a template for your new file, select iOS at the top, and then Swift File. Then, hit Next.
- Name this file LocationDataManager, and then hit Create.
- 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 {
...