I have a fast iOS application using a real-time Firebase database. If I usually use the application, I still can not find any problems. However, I want to expect extreme cases.
I am trying to emphasize a test application before I click update, and one of the ways I do it is quickly moving from VC using tableView to the next VC, which is a detailed VC. If I do this several times, the table view will show a lot of duplicate data.
I tested my application by opening a table view on my simulator and going to my Firebase Console and manually changing the value, and the line instantly changed on the device.
Therefore, I am confused why in my table view the wrong number of children is displayed if it constantly checks what value should be.
// MARK: Firebase Methods func checkIfDataExits() { DispatchQueue.main.async { self.cardArray.removeAll() self.ref.observe(DataEventType.value, with: { (snapshot) in if snapshot.hasChild("cards") { self.pullAllUsersCards() } else { self.tableView.reloadData() } }) } } func pullAllUsersCards() { cardArray.removeAll() let userRef = ref.child("users").child((user?.uid)!).child("cards") userRef.observe(DataEventType.value, with: { (snapshot) in for userscard in snapshot.children { let cardID = (userscard as AnyObject).key as String let cardRef = self.ref.child("cards").child(cardID) cardRef.observe(DataEventType.value, with: { (cardSnapShot) in let cardSnap = cardSnapShot as DataSnapshot let cardDict = cardSnap.value as! [String: AnyObject] let cardNickname = cardDict["nickname"] let cardType = cardDict["type"] let cardStatus = cardDict["cardStatus"] self.cardNicknameToTransfer = cardNickname as! String self.cardtypeToTransfer = cardType as! String let aCard = CardClass() aCard.cardID = cardID aCard.nickname = cardNickname as! String aCard.type = cardType as! String aCard.cStatus = cardStatus as! Bool self.cardArray.append(aCard) DispatchQueue.main.async { self.tableView.reloadData() } }) } }) }
source share