ios - 使用 PFFile 管理子类 PFUser 的个人资料图片 - Swift/iOS

标签 ios swift parse-platform pfuser pffile

我在我的 iOS 应用程序中对 PFUser 进行了子类化,并使用此函数来获取个人资料图片。 profilePicture@NSManaged PFFileprofilePictureImage 是 UIImage。

除了 getData()fetchIfNeeded() 是主线程上潜在的长时间运行操作这一事实之外,这非常有效。

任何人都可以想出一个好方法来实现此方法,以便可怕的部分在后台线程上运行吗?

谢谢!

func image() -> UIImage!
{
    if !(self.profilePictureImage != nil)
    {
        if self.profilePicture != nil
        {
            self.fetchIfNeeded()
            if let data = self.profilePicture!.getData() {
                self.profilePictureImage = UIImage(data: data)
                return self.profilePictureImage
            }
        }else {
            return UIImage(named: "no_photo")!
        }
    }
    return self.profilePictureImage
}

最佳答案

更改方法,以便不返回图像,而是采用一个闭包,当图像可用时调用该闭包并将其作为参数传递。如果需要下载图像,则可以立即调用此函数,也可以在延迟一段时间后调用此函数。

关于ios - 使用 PFFile 管理子类 PFUser 的个人资料图片 - Swift/iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31011095/

相关文章:

ios - 无法从 NSDictionary iOS 获取所有匹配字符串

swift - 当在 swift 3 中加载所有数据时,如何在 tableview 中隐藏刷新控件?

ios UI 对于我的 Storyboard来说不可扩展

ios - PFQuery includeKey 给出命令

ios - Facebook 登录问题 - canOpenURL : failed for URL: "fbauth2:///" - error: "(null)"

ios - 在应用程序中存储短音频文件/流

ios - 在前台和后台无限运行任务

ios - 核心数据迁移: How should i change the data type from bool to int in next version

ios - Swift 中 Segue Unwind 的解决方法未触发

ios - 如何通过 Google Sheets API 进行基本写作?