I wanna change global variable 'isRiskLocation' in docRef.getDocuments { ~ }
Can you give me advice?
func checkRiskLocationAleadyExist(database: Firestore!, latitude: Double, longitude: Double) -> Bool {
var isRiskLocationExist: Bool = false
let docRef = database.collection("collectionName")
.whereField("latitude", isEqualTo: latitude)
.whereField("longitude", isEqualTo: longitude)
docRef.getDocuments { (querysnapshot, error) in
guard let data = querysnapshot?.documents else {return }
isRiskLocationExist = data.isEmpty // This is not working. I hope to change 'isRiskLocation' value depending on "data.isEmpty"
}
print(isRiskLocationExist) <-- This is only print "false"
return isRiskLocationExist
}