Skip to content

Instantly share code, notes, and snippets.

@aguidis
Created December 28, 2017 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aguidis/749786665c69c9f7e92d212d6a583f09 to your computer and use it in GitHub Desktop.
Save aguidis/749786665c69c9f7e92d212d6a583f09 to your computer and use it in GitHub Desktop.
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