【发布时间】:2015-12-29 18:55:57
【问题描述】:
我有一个使用 Parse 存储个人资料图片的 Swift 项目。出于某种原因,PFFile 配置文件图像很难开始工作。我终于用这个功能让它在 Swift 1.2 中工作了:
func image(completion: (image: UIImage) -> Void)
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), {
if self.profilePictureImage == nil
{
if self.profilePicture != nil
{
self.fetchIfNeeded()
if let data = self.profilePicture!.getData()
{
self.profilePictureImage = UIImage(data: data)
}
}else
{
self.profilePictureImage = UIImage(named: "no_photo")!
}
}
dispatch_async(dispatch_get_main_queue(),{
completion(image: self.profilePictureImage)
})
})
}
profilePicture 是@NSManaged PFFile
profilePictureImage' is aninternal UIImage`
我已将项目迁移到 Swift 2.0,但它在 completion 调用时因 unwrapped nil 错误而崩溃。
发生了什么变化?我该如何解决这个问题?谢谢!
【问题讨论】:
标签: ios swift parse-platform swift2 pffile