0

In my root view controller, in viewWillAppear, I'm calling observe(.childAdded..., which is supposed to append the data from a newly added child from Firebase to an array. I also remove the observer in viewDidDisappear. I'm printing the size of the array every time it gets modified (via didSet) and every time I re-enter the controller's view, the size of the array indicates that all the same data was appended again. i.e. if there are 5 children, the array.count reads 5 on the first appearing of the controller, and 10 on the second appearing of the controller. Clearly, already loaded data is being loaded in again. How can I make it so that the only data to be appended is new data, even after the controller's view has been left and returned to? Thanks.

Archie Gertsman
  • 1,601
  • 2
  • 17
  • 45
  • We need to see your code to understand exactly what's going on, but it sounds like a duplicate per the above comment. Please take some time and review [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) and [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – Jay Aug 21 '17 at 17:01
  • You really need to post your code, but your array is repopulating probably because when you add the observer again, it repopulates from firebase and adds the objects again. You can correct it simply by setting the array to empty like myArray = []. Or, ensure the viewController that's storing the array is being released. – Jay Aug 21 '17 at 20:35

0 Answers0