ios - 为什么图像没有被添加到数组中?

标签 ios swift parse-platform

我正在尝试附加从解析数据库检索到的图像,但没有将任何内容添加到 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/

相关文章:

ios - 将数据从 uitableview 传递到其他 uiview

使用嵌套框架的 iOS 问题

ios - 如何更改 Swift header ("ProductModuleName-Swift.h") 产品名称作为产品名称动态变化

带有 nil 值的 Swift 闭包捕获列表

swift - 如何更新 firebase 查询?

android - "at least one ID field (installationId,deviceToken) must be specified in this operation"解析

ios - fatal error : unexpectedly found nil while unwrapping an Optional value Parse sign up

ios - 使用完整的 PFUser 信息查询 PFObject

ios - UIAlertController作为接受功能参数的实用程序

ios - UIUserNotificationType