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

php - Hide output during test execution -

javascript - Migrate custom AngularJS filter from 1.2.28 to 1.4.x -

Update Magento products with multiple images -