I want to sort my TableView by distance, but I have mixed up:( Please help me if You can, I would appreciate it, really :(
I have an array with 100 objects.
Use of unresolved identifier 'mall'
=> There is nothing named "mall" in the scope of the function locationManager didUpdateLocations
. Meaning: locationManager didUpdateLocations
has no clue what happens inside of tableView cellForRowAt indexPath
and vice versa.
You could solve this problem by applying following steps to your code:
locationManager didUpdateLocations
tableView cellForRowAt indexPath
add a property to your class that stores the current position:
var currentPosition: CLLocation? = nil
Store the position you receive in locationManager didUpdateLocations
to the currentPosition
property
self.tableView.reloadData()
after you received and assigned the position mall
and the currentPosition
in cellForRowAt
to calculate the distance and update the distanceLabel
currentPosition
can be nil
and the distance can not be calculated => make label empty or add something like "unknown distance" to it