I am making an app where this block of code runs:
extension LikeOrDislikeViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let uid = Auth.auth().currentUser?.uid
var numRows = 0
Database.database().reference().child("Num Liked").child(uid!).observeSingleEvent(of: .value, with: { (snapshot) in
if let dictionary = snapshot.value as? [String: AnyObject] {
let numMoviesLiked = ((dictionary["Number of Movies Liked"] as? Int))!
if numMoviesLiked % 4 == 0 {
numRows = numMoviesLiked/4
}
}
})
return numRows
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.backgroundColor = UIColor.red
tableView.rowHeight = 113
cell.textLabel?.text = "\(indexPath.row)"
return cell
}
}
I need the "Database.database..." code to run before the return line. How can I do this?