ios - Having issue with asynchronous processing using Parse -


i have parse database has records consisting (among other items) of pffile items of thumbnail images. database read-only , created using program. confirmed thumbnails in parse. when try retrieve thumbnails using function shown below, notification before images processed resulting on occasional failures based on timing of post-notification processing. how can ensure records processed?

    func convertpfilestoimages () {     println("convertpfilestoimages")     let notification = nsnotification(name: "imagesloaded", object: self)     in 0 ..< records.count {         let userimagefile = records[i].icon         records[i].image = uiimage()         println("name: \(self.records[i].name) image: \(self.records[i].image)")         userimagefile.getdatainbackgroundwithblock {             (imagedata: nsdata?, error: nserror?) -> void in             if error == nil {                 //println("no error")                 if let imagedata = imagedata {                     let image = uiimage(data:imagedata)!                      self.records[i].image = image                     // println below shows not images converted                     println("name: \(self.records[i].name) image: \(self.records[i].image)")                 }             } else {                 println("parseprocessing-converttoimage: error = \(error)")             }             if (i == self.records.count-1) {                 println("all images processed")                 // loop done before images processed                 nsnotificationcenter.defaultcenter().postnotification(notification)             }          }     }  } 

your for() loop executes async code, problem getdatainbackground.

when i == self.records.count-1 doesn't guarantee calls have finished up.

getdatainbackround should converted getdata (or parse named synchronous call), , whole method should called in background thread.

you use nsoperationqueue load simultaneously, , call [queue waituntilfinished].


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -