I have an array that loads all users into a user list array and I'm wondering if each each time the array gets loaded, it counts as 1 read or does every element in the array count was its own read?
var userList = [User]()
func addUserObserver(_ update: @escaping () -> Void) {
FriendSystem.system.USER_REF.getDocuments { snapshot, error in
self.userList.removeAll()
guard error == nil else {
#if DEBUG
print("Error retreiving collection")
#endif
return
}
let group = DispatchGroup()
for document in snapshot!.documents {
let email = document.get("email") as! String
let username = document.get("username") as! String
group.enter()
if email != Auth.auth().currentUser?.email! {
self.userList.append(User(userEmail: email, userID: document.documentID, userName: username))
group.leave()
}
}
group.notify(queue: .main) {
update()
}
}
}
group.leave()inifcondition .. your application can crash - Jawad Ali