I have a Swift project that uses Parse to store profile pics. For some reason the PFFile profile image was a pain to get working. I finally got it working in Swift 1.2 with this function:
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
is the @NSManaged PFFile
profilePictureImage' is an
internal UIImage`
I've migrated the project to Swift 2.0 and it's crashing with an unwrapped nil error on the completion
call.
What's changed? How can I address this? Thanks!