I am making a completion handler for a function which will return a list of objects. When it return value for first time, it works well. But when any change happen into fire
This line stadiumRef.observe(.value, with: { (snapshot) in ...
actually adding an observer that will be called everytime your stadium data is changed.
Because you called it twice by using getStadiums(){ stadiums ...
, the total observer added will be 2.
That makes the line stadiums.append(stadium)
called twice in the second call.
My suggestion would be to use stadiumRef.observe()
once without calling it from getStadiums()
.