ios - Inserting into CollectionView throws Invalid Update Error -


i using new firebase , i'm making many calls database 1 after retrieve object. in callback, added object collectionview datasource , call collectionview.insertitemsatindexpaths.

but i'm getting invalid update error. i'm guessing because items being retrieved fast database last update hasn't completed before next 1 starts. how can fix this?

also, should dispatch_async main thread inside callback, right?

the solution simple if problem queries called before previous completed.

you put every function query completion (except last one) , call them 1 one.

let's have 2 queries queryone , querytwo.

func queryone(completion: result<void> -> void)  {  //below line complete query  //usually after loop if have completion(.success())  }  func querytwo()  {   } 

now have synchronize them in viewdidload

queryone() { result in             switch result {             case .success:                 self.locationmanager.delegate = self                 querytwo()              case .failure( _): break // handle error             }            } 

Comments