Last active
February 3, 2017 17:52
-
-
Save leontiy/104e6435b4ce3627b724a9d25bd7d9e8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
final class ProductTableViewCell: UITableViewCell { | |
@IBOutlet var label: UILabel! | |
@IBOutlet var imageView: UIImageView! | |
@IBOutlet var titleLabel: UILabel! | |
let viewModel: MutableProperty<Product?> | |
var disposable: Disposable? | |
deinit() { | |
disposable?.dispose() | |
} | |
func awakeFromNib() { | |
super.awakeFromNib() | |
self.viewModel.producer.startWithValues { [weak self] maybeAViewModel in | |
if let aViewModel = maybeAViewModel { | |
self?.titleLabel.text = aViewModel.title | |
self?.label.text = aViewModel.text | |
self?.disposable?.dispose() | |
self?.imageView.image = nil // display a placeholder | |
self?.disposable = downloadImage(aViewModel.imageUrl).startWithValues { | |
[weak self] anImage in | |
self?.imageView.image = anImage | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment