Last active
April 9, 2019 08:55
-
-
Save ashour/6488e13cb275c96de885d8802b58d5b2 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 | |
class FeedViewController: | |
UIViewController, | |
UITableViewDataSource | |
{ | |
@IBOutlet weak var feedTableView: UITableView! | |
fileprivate var productListener: Product.Listener? | |
fileprivate var products: [Product] = [] | |
{ | |
didSet | |
{ | |
feedTableView.reloadData() | |
} | |
} | |
override func viewWillAppear(_ animated: Bool) | |
{ | |
super.viewWillAppear(animated) | |
productListener = Product.listenToFeed | |
{ | |
[unowned self] in self.products = $0 | |
} | |
} | |
override func viewWillDisappear(_ animated: Bool) | |
{ | |
super.viewWillDisappear(animated) | |
productListener?.remove() | |
} | |
func tableView(_ tableView: UITableView, | |
numberOfRowsInSection section: Int) | |
-> Int | |
{ | |
return products.count | |
} | |
func tableView(_ tableView: UITableView, | |
cellForRowAt indexPath: IndexPath) | |
-> UITableViewCell | |
{ | |
let cell = tableView.dequeueReusableCell(withIdentifier: "CELL") as! | |
FeedTableViewCell | |
cell.updateUI(with: products[indexPath.row]) | |
return cell | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment