I have a Firebase database with nested dictionaries attached to the Firebase autoId() method.
Snap (donators-items) {
"-LjGwJLdBoFugIaPMVJg" = {
description = "Yummy Pasta";
latitude = "44.93926644825692";
longitude = "4.872616600173217";
name = "Pasta";
pickUpDate = "2019-07-09T16:15:53+02:00";
selectedType = "Food";
};
"-LjGwWkbOzeXJ6U3JO7r" = {
description = "Brand new shirt";
latitude = "44.93607125515575";
longitude = "4.878479988801786";
name = "Cool T-shirt";
pickUpDate = "2019-07-12T16:15:41+02:00";
selectedType = "Clothes";
};
}
I am using this method to retrieve the database dictionary.
var donatorsItems = [DonatorItem]()
func fetchDonatorsItemsFromFirebase() {
donatorsItems.removeAll()
rootRef.child(FirebaseRoot.donatorsItems.rawValue).observe(.value) {
(snapshot) in
if let idDict = snapshot.value as? NSDictionary {
let ids = idDict.allKeys
for key in ids {
if let nestedDict = idDict[key] as? FirebaseDictionary {
print(nestedDict)
}
}
}
}
}
When printing nestedDict, I populate two nested dictionary in an unordered collection.
How can I retrieve the datas to add it to my DonatorItem object and send it in an order from closer to further using the latitude and longitude of each object?
I have created the function that calculates the distance between the user and the latitude, longitude of the object.
func getDistanceFromUserToMeetingPoint(_ meetingPointLatitude: Double, _ meetingPointLongitude: Double, vc: UIViewController) -> Double