Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import UIKit
import Parse
class HomeWorkoutCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var focusLabel: UILabel!
@IBOutlet weak var durationLabel: UILabel!
@IBOutlet weak var coverImage: UIImageView!
var viewModel: HomeWorkoutCellViewModel? {
didSet {
bindViewModel()
}
}
private func bindViewModel() {
self.nameLabel?.text = viewModel?.name
self.focusLabel?.text = viewModel?.focus
self.durationLabel?.text = viewModel?.durationText
DispatchQueue.global(qos: .userInteractive).async { [weak self] in
// Async background process
if let imageFile : PFFile = self?.viewModel?.cover {
imageFile.getDataInBackground(block: { (data, error) in
if error == nil {
DispatchQueue.main.async {
// Async main thread
let image = UIImage(data: data!)
self?.coverImage.image = image
}
} else {
print(error!.localizedDescription)
}
})
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.