Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- import Firebase
- class MainViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
- @IBOutlet weak var tableView: UITableView!
- var items = [String]()
- override func viewDidLoad() {
- super.viewDidLoad()
- tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
- tableView.delegate = self
- tableView.dataSource = self
- let db = Firestore.firestore()
- db.collection("items").getDocuments() { (querySnapshot, err) in
- if let err = err {
- print("Error getting documents: \(err)")
- } else {
- for document in querySnapshot!.documents {
- if let name = document.data()["name"] as? String {
- self.items.append(name)
- }
- }
- self.tableView.reloadData()
- }
- }
- }
- func numberOfSectionsInTableView(tableView: UITableView) -> Int {
- return 1
- }
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return items.count
- }
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as UITableViewCell
- cell.textLabel?.text = items[indexPath.row]
- return cell
- }
- }
Add Comment
Please, Sign In to add comment