Completion handler Firebase observer in Swift

后端 未结 4 1450
日久生厌
日久生厌 2021-01-17 01:11

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

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-17 01:23

    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().

提交回复
热议问题