2

I have created a var userImages = [PFFile]() and have appended the respective user images from Parse via a user query and self.userImages.append(user["imageFile"] as! PFFile). This works fine. However, when I try to set the image of the user via

userImages.getDataInBackGroundWithBlock{ (data, error) -> Void in ...

I'm receiving the following error: **'[(PFFile)]' does not have a member named 'getDataInBackGroundWithBlock'**

Why doesn't this work and what might be a solution for this issue?

Thank you for the help!!

enter image description here

enter image description here

GLS
  • 831
  • 6
  • 8

1 Answers1

1

You are trying to call getDataInBackGroundWithBlock in a array try to use"

userImages.last?.getDataInBackGroundWithBlock{...}

or you can save it in a variable and use the new PFFIle to retrieve the image

let userImage = user["imageFile"] as! PFFile
userImage.getDataInBackGroundWithBlock{...}

or access it directly using:

(user["imageFile"] as! PFFile).getDataInBackGroundWithBlock{...}

The role process being:

self.userImages.append(user["imageFile"] as! PFFile) //This is just a reference to download the image

userImages.last?.getDataInBackgroundWithBlock {
  (imageData: NSData?, error: NSError?) -> Void in
  if error == nil {
    if let imageData = imageData {
        let image = UIImage(data:imageData) // this is the final image
    }
  }
}
Icaro
  • 14,585
  • 6
  • 60
  • 75
  • Thank you for your fast answer! userImages.last? doesn't show me an image, but it's more or less exactly what I'm trying to do. Is there any other way to access the first Image or PFFile from my array, such as userImages[indexPath.row] (Using indexPath results in the error: is unresolved identifier) ? Unfortunately your other suggestions are not retrieving any images from my array. – GLS Jun 08 '15 at 07:35
  • Sorry I may had expressed myself poorly, I wasn't sure what you want to do so I show you few options, just the first uses an array, the other two are just a more direct approach. Parse does not send you an image at first but a link to an image, the final image will be retrive from the getDataInBackGroundWithBlock block – Icaro Jun 08 '15 at 07:42
  • Really appreciate your help! I used your code to retrieve the files, but no picture shows up in the UIImageView. Here are my two codes that I use for the Query and Retrieving of the images. I'm looking for any mistakes but the code seems to be fine...Maybe something with my approach to it might be wrong. I will provide a link to the screenshots of the code shortly. – GLS Jun 08 '15 at 08:19
  • I just edited my post and provided you the screenshot to my code. Hope this helps and we can figure this out – GLS Jun 08 '15 at 08:21