Search code examples
iosswiftuitableviewkinvey

How to update tableviewcell using asynchronous methods in Swift 2.0?


as the title says, I am trying to fetch data from Kinvey and load the data I get to the table view. However, since all the query methods are asynchronous, I can't get the data until the table view finish loading.

Is there any way to wait for the completion block to finish then proceed to the next line of code where I load the data to table view cells?

Here is the method from kinvey that I need to use to get the data, and the completionblock only gets called after everything else finishes

     store.queryWithQuery(
     query, 
     withCompletionBlock: {()-> }
     )

Solution

  • Do This:

    store.queryWithQuery(
             query, 
             withCompletionBlock: {(/*here should be as pramater dataReturned*/)-> in
    //assign self.data = dataReturned
            self.tableView.reloadData()
            })