Last active
February 3, 2017 17:52
-
-
Save leontiy/c46b2aa62c1c62cc4268e4ba98f27482 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
| // View Model layer | |
| final class Product { | |
| let title: String | |
| let text: String | |
| let imageUrl: URL | |
| // ... | |
| } | |
| // Networking layer | |
| func downloadImage(url: URL) -> SignalProducer<UIImage, NSError> { | |
| // ... | |
| } | |
| // View layer | |
| final class ProductTableViewCell: UITableViewCell { | |
| @IBOutlet var label: UILabel! | |
| @IBOutlet var titleLabel: UILabel! | |
| @IBOutlet var imageView: UIImageView! | |
| let viewModel: MutableProperty<Product?> | |
| 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 | |
| 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