【发布时间】:2015-11-19 02:12:54
【问题描述】:
我的问题:知道最后一张图片何时下载的最佳方法是什么,因为一旦下载了所有文件,我就需要更新 UI。
我正在从 Parse 下载一组 PFFile。我现在正在做的是:以这种方式从解析中获取 PFFiles 数组
func getAllUserPictures(completion: (imageFiles: [PFFile]) -> Void) {
guard let id = currentUserID else {
return
}
let query = PFQuery(className: "Profile")
query.whereKey("objectId", equalTo: id)
query.includeKey("avatars")
query.findObjectsInBackgroundWithBlock { profile, error in
guard let imageFiles = profile?.first?.objectForKey("avatars") as? [PFFile] else {
return
}
completion(imageFiles: imageFiles)
}
}
从完成处理程序获得 imageFile 数组后,我会继续以这种方式下载它们:
func getUserPicturesWithBlock(completion: (result: [UIImage]) -> Void) {
DataManager.sharedInstance.getAllUserPictures { imageFiles in
for file in imageFiles {
file.getDataInBackgroundWithBlock({ data, error in
guard let data = data, let image = UIImage (data: data) else{
return
}
self.imagesArray.append(image)
})
}
}
}
【问题讨论】:
标签: ios swift parse-platform cloud background-process