Coding the initial view controller
The
InitialViewController
class will display the possible cities where the user is located. Let's continue with the InitialViewController
class and complete its code. To complete this code, we need to think about where we are going to store the received information. We will need two arrays of CityInfo
: one is to store every object received from the server and the other is to store the objects that are shown after the user's filter. These arrays must be stored as properties:
private var cities = [CityInfo]() private var citiesDisplayed = [CityInfo]()
At this point, we can complete the didUpdateLocations
method, which belongs to the CLLocationManagerDelegate
protocol. Now, we can request information of the cities that are around us. Type the following code to implement the didUpdateLocations
method, replacing the yourgeonamesuser
word with the username you registered on geonames:
func locationManager(manager: CLLocationManager!, didUpdateLocations...