0

I am having some trouble converting a PFFile array (named: activeimageFilearray) into a UIImage array (named: activeImageArray). My current for-in method only appends the first entry of the PFFile rather than appending all the entires in the PFFile array into my new UIImage array. So when i execute the last line of code, it would show [fatal error: Array index out of range] as the UIImage array only has one value. Thanks in advance.

for x in self.activeimageFileArray
{
x.getDataInBackgroundWithBlock({ (imageData: NSData?, error: NSError?) -> Void in
if error == nil
{
let image = UIImage(data: imageData!)
self.activeimageArray.append(image!)
}
println(self.activeimageArray)
self.venueImage.image = self.activeimageArray[1]

})
}
bantukatanaya
  • 93
  • 1
  • 10

2 Answers2

0

This is probably a concurrency issue, because the line that you have printing out the contents of the image will be executed before the callback finishes, that's the nature of backgrounding a task. If you really want to see the printed contents of the image, you could print it inside the callback , or completely outside of the for loop.

pbush25
  • 5,228
  • 2
  • 26
  • 35
0

First you have to use ParseUI so you can use PFImageView

pod 'ParseUI'

in Your class import ParseUI

import UIKit
import ParseUI
import Parse

class ViewController: UIViewController {

var Obj = PFObject(className: "classname")

 @IBOutlet weak var venueImage: PFImageView!

 override func viewDidLoad() {
    super.viewDidLoad() 

// loading image form PFFile Array 
 let images = Obj["images"] as! [PFFile]
 let image = images[0] as PFFile
 self.venueImage.file = image
 self.venueImage.loadInBackground()

    }

}
Faris
  • 1,206
  • 1
  • 12
  • 18