parse.com - Progress Block runs too many times - swift -



parse.com - Progress Block runs too many times - swift -

i using block bring in uimages parse.

for object in objects { allow thumbnail = object["staffpic"] pffile thumbnail.getdatainbackgroundwithblock({ (imagedata: nsdata!, error: nserror!) -> void in if (error == nil) { allow image = uiimage(data:imagedata) } }, progressblock: {(percentdone: cint) -> void in self.logoimages.append(self.image) }) }

problem is, runs progressblock 6 times (if there 6 images in query). need run progressblock 1 time when done.

any ideas ?

the progressblock of pffile's getdatainbackgroundwithblock:progressblock: used progress of individual files beingness downloaded, not way know when downloads have completed. called more 6 times when downloading single file. shouldn't appending self.image self.logoimages there, should done in result block after create image imagedata.

for object in objects { allow thumbnail = object["staffpic"] pffile thumbnail.getdatainbackgroundwithblock({ (imagedata: nsdata!, error: nserror!) -> void in if (error == nil) { allow image = uiimage(data:imagedata) self.logoimages.append(image) } }, progressblock: {(percentdone: cint) -> void in // update ui download progress here (if needed) }) }

now, seem asking way know when of downloads have completed. utilize dispatch groups that. basic steps are:

create dispatch_group_t for each download: call dispatch_group_enter do download call dispatch_group_leave when download complete call dispatch_group_notify block should called when downloads complete.

it this:

let downloadgroup = dispatch_group_create() object in objects { allow thumbnail = object["staffpic"] pffile dispatch_group_enter(downloadgroup) thumbnail.getdatainbackgroundwithblock({ (imagedata: nsdata!, error: nserror!) -> void in if (error == nil) { allow image = uiimage(data:imagedata) self.logoimages.append(image) dispatch_group_leave(downloadgroup) } }, progressblock: {(percentdone: cint) -> void in // update ui download progress here (if needed) }) } dispatch_group_notify(downloadgroup, dispatch_get_main_queue()) { // called when downloads finish }

swift parse.com

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -