image - PFFile to UIImage in Parse (ios) -
i trying convert pffile uiimage. works, however, doesn't seem run until end. line after image called appends image array (photosarray.append(image!)), when this, doesnt work, , stores nothing. believe because since image hasnt been retrieved yet because grabbing image in background. how not have save in background, wait until data loaded, append photosarray image, array isnt empty?
var photosarray = [uiimage]() let photosvalue = log["images"] as! pffile photosvalue.getdatainbackgroundwithblock({ (imagedata: nsdata?, error:nserror?) -> void in if (error == nil) { let image = uiimage(data:imagedata!) //line below appends nothing! photosarray empty array, [] photosarray.append(image!) //following line of code doesnt run until end. last line printed in console. println("our image: \(image)") } }) //prints "[]", no value println(photosarray) println("our image array^^") } //after code ran, println("our image: \(image)") run, //and "our image: optional(<uiimage: 0x16f0ead0>, {394, 256})". //this last line of console logged, saving, not until end.
that not correct assumption, whole point of getdatainbackgroundwithblock handle response data. wouldn't able assign
let image = uiimage(data: imagedata!)
if nil.
i'm not sure println statements you're referring to, printing out array while data still being collected in background may not give result, , just
[]
but should see
println("our image: \(image)")
if plan display these images inside uiimageview suggest taking @ parseui class pfimageview, has property can assign pffile , method in load it.
Comments
Post a Comment