multithreading - Getting information from background thread onto the main thread for Swift -


i seem having trouble getting information global queue main queue.

override func viewdidload() {     super.viewdidload()      dispatch_async(dispatch_get_global_queue(int(qos_class_user_interactive.value), 0)) {         let query = pfquery(classname: "venuedata")         query.wherekey("name", equalto: "sedona")         var object = query.findobjects()         if let myobject = object as? [pfobject] {             x in myobject {                 var hotellabel: string? = x.objectforkey("name") as? string                 println(hotellabel)                 dispatch_async(dispatch_get_main_queue()) {                     self.new = hotellabel!                     self.hotelarray.append(self.new)                 }             }         }     } } 

even though able change ui through dispatch_get_main_queue, seem having trouble updating other stuff (e.g. array) , if println(hotelarray) outside of block, empty array show up.

i understand happens because mainthread loads faster time takes background thread load data. puzzles me seems if hotel array not updated regardless of happens inside dispatch_get_main_queue whereas ui related stuff such uilabels updates accordingly. appreciated.


Comments