-
-
Save aguidis/749786665c69c9f7e92d212d6a583f09 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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