我正在尝试附加从解析数据库检索到的图像,但没有将任何内容添加到 UIImage 数组中。如何附加检索到的图像?
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()
}
})
}
}
}
最佳答案
代码不是问题,问题出在 Xcode,这里是任何有同样问题的人的解决方案。 The resource could not be loaded because the App Transport Security policy requires the use of a secure connection
关于ios - 为什么图像没有被添加到数组中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33355128/