0

I'm trying to append images retrieved from parse database, but nothing is being added to the UIImage array. How do I append the retrieved images?

 var arrayOfFriends: [UIImage] = []

 func getFriendPic(){

    var imagequery = PFQuery(className: "_User")
    imagequery.findObjectsInBackgroundWithBlock {( objects: [AnyObject]?, error: NSError?) -> Void in
        for object in objects!{
            let userPic = object["ProPic"] as! PFFile
            userPic.getDataInBackgroundWithBlock({ (imageData: NSData?, error: NSError?) -> Void in
                if(error == nil){
                    let image = UIImage(data: imageData!)
                    //breakpoint placed on line below, but app crashes with array out of bounds.
                    self.arrayOfFriends.append(image!)
                    print(self.arrayOfFriends)
                }
                dispatch_async(dispatch_get_main_queue()) {
                    self.collectionView.reloadData()
                }
            })

        }
    }
}
xxtmanxx
  • 209
  • 2
  • 8

1 Answers1

0

The code was not the problem, it was Xcode, here is the solution to anybody who has the same problem. The resource could not be loaded because the App Transport Security policy requires the use of a secure connection

Community
  • 1
  • 1
xxtmanxx
  • 209
  • 2
  • 8