title: Swift how to add 5 star ratings for users to vote using Firebase
body: <p>I'm creating a restaurant rating app in Swift that allows its users to rate restaurants on a 5-star rating scale (just like Zomato and Yelp) .
  I will be using Firebase to store each user's rating for a specific restaurant and then take the average of user ratings and display it in the app. There will be a star rating corresponding to each tableview cell (every tableview cell corresponds to a restaurant) .</p>
  
  <p>However I'm stuck deeply on the project. I can't figure out how to add the user's rating to the database. My app won't require a user sign-up or login page, users can directly rate restaurants. This being said, also, how can I make sure that users can vote only once for a single restaurant? I'd appreciate any help! Thank you in advance.</p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>var starsRating = 0
  var starsEmptyPicName = "star" // can change to empty star picture name
  var starsFilledPicName = "starfill" // can change to filled star picture name
  override func draw(_ rect: CGRect) {
  let starButtons = self.subviews.filter{$0 is UIButton}
  var starTag = 1
  for button in starButtons {
      if let button = button as? UIButton{
          button.setImage(UIImage(named: starsEmptyPicName), for: .normal)
          button.addTarget(self, action: #selector(self.pressed(sender:)), for: .touchUpInside)
          button.tag = starTag
          starTag = starTag + 1
      }
  }
  setStarsRating(rating:starsRating)
  }
  
  func setStarsRating(rating:Int){
  self.starsRating = rating
  let stackSubViews = self.subviews.filter{$0 is UIButton}
  for subView in stackSubViews {
      if let button = subView as? UIButton{
          if button.tag &gt; starsRating {
              button.setImage(UIImage(named: starsEmptyPicName), for: .normal)
          }else{
              button.setImage(UIImage(named: starsFilledPicName), for: .normal)
          }
      }
    }
   }
  
  @objc func pressed(sender: UIButton) {
      setStarsRating(rating: sender.tag)
  
   }
  } 
  </code></pre>
  
  <p>And here are my tableview functions:</p>
  
  <pre><code>  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int{
   return identifiers.count //identifiers is my big restaurants array
  }
  
  
  
   func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell{
  
          let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "CellThree")
          cell.textLabel!.text = identifiers[indexPath.row]
          return cell
      }
  </code></pre>