이 줄 stadiumRef.observe(.value, with: { (snapshot) in ...
같은
func getStadiums(complition: @escaping ([Stadium]) -> Void){
var stadiums: [Stadium] = []
let stadiumRef = Database.database().reference().child("Stadium")
stadiumRef.observe(.value, with: { (snapshot) in
for snap in snapshot.children {
guard let stadiumSnap = snap as? DataSnapshot else {
print("Something wrong with Firebase DataSnapshot")
complition(stadiums)
return
}
let stadium = Stadium(snap: stadiumSnap)
stadiums.append(stadium)
}
complition(stadiums)
})
}
그리고 호출은 실제로 매번 당신의 경기장 데이터가 변경 될 때 호출됩니다 관찰자를 추가. 당신이 getStadiums(){ stadiums ...
를 사용하여 두 번 호출하기 때문에
추가, 총 관찰자는 두 번째 호출에 두 번 호출 라인 stadiums.append(stadium)
한다 2.
될 것입니다.
내 제안은 getStadiums()
에서 전화하지 않고 stadiumRef.observe()
을 한 번 사용하는 것입니다.
감사합니다. @Jen :) 정말 효과가 있습니다. –