ios - Accessing Data Outside of Closure -


i have array in class i'm trying fill within closure. however, when try access/print array contents, seems empty outside of closure. how store data use outside of closure?

for index in 0..<6 {         let picnumber = index + 1         if let pica = currentuser.objectforkey("pic\(picnumber)") as? pffile {             pica.getdatainbackgroundwithblock({ (data:nsdata!, error:nserror!) -> void in                 if error == nil {                     self.pic1 = uiimage(data: data)                     var images = scaleimage(self.pic1!, and: 200)                     self.imagesforsection0.append(images)                 }             })             println(self.imagesforsection0)         }     } 

it not empty outside closure

the method getdatainbackgroundwithblock async,it means return first.so,you see nothing in print function.

document

asynchronously gets data cache if available or fetches contents network.

edit

for index in 0..<6 {     let picnumber = index + 1     if let pica = currentuser.objectforkey("pic\(picnumber)") as? pffile {         pica.getdatainbackgroundwithblock({ (data:nsdata!, error:nserror!) -> void in             if error == nil {                 self.pic1 = uiimage(data: data)                 var images = scaleimage(self.pic1!, and: 200)                 self.imagesforsection0.append(images)             }         println(self.imagesforsection0)         //then call reload data         })     } } 

Comments

Popular posts from this blog

python - jinja2: TemplateSyntaxError: expected token ',', got 'string' -

node.js - NodeJS remote terminal to Dropbear OpenWRT-Server -

Qt4: how to send QString inside a struct via QSharedMemory -