title: How to hide uibutton if its title text is empty or unassigned?
body: <p>The code and question represents an Xcode project in Swift. I have a a group of buttons that display options according to which text is presented on a label. </p>
  
  <p>The label text is derived from the keys of a dictionary and the button texts are derived from the values of that same dictionary. The dictionary type is <code>[String: [String]</code>. The keys and values are both placed in arrays. I currently display the correct data but some values differ in length than others. </p>
  
  <p>For example one key has 3 values and another key has 5. I want to hide the buttons if there is not text to send to it. So if a key is presented in a label and has 3 values I only want to display 3 buttons and so. What would be the best way to achieve this functionality? Here is my code that is not achieving want I want to accomplish:</p>
  
  <pre><code>func startSurvey() {
  
      if surveyQuestions.isEmpty {
          surveyQuestions = Array(SampleSurvey().surveyquestions.keys)
          print(surveyQuestions)
      }
  
      let rand = Int(arc4random_uniform(UInt32(surveyQuestions.count)))
      questionTitle.text = surveyQuestions[rand]
  
      var choices = SampleSurvey().surveyquestions[surveyQuestions[rand]]!
      print(choices)
      print(choices.count)
      surveyQuestions.remove(at: rand)
  
      var button = UIButton()
      var x = 0
   // var choicePool = choices.count
  
      if choices.count == 2 {
          for index in 1...2 {
              button = view.viewWithTag(index) as! UIButton
              button.setTitle(choices[x], for: .normal)
              x += 1
              if button.titleLabel?.text.isEmpty == true {
                  button.isHidden = true
              }
          }
      }
  
      else if choices.count == 4 {
      for index in 1...4 {
          button = view.viewWithTag(index) as! UIButton
          button.setTitle(choices[x], for: .normal)
          x += 1
  
          if button.titleLabel?.text.isEmpty == true {
              button.isHidden = true
          }
  
      }
  }
  </code></pre>
  
  <p>Here is a screenshot of the simulator, as you can see this particular key has only 2 values so there are 3 blank buttons, I want to hide the buttons that are blank:</p>
  
  <p><img src="https://i.stack.imgur.com/Lp2z7.png" alt="screenshot of simulator"></p>
  
  <p>UPDATE: The following code has granted me the functionality I was aiming for:</p>
  
  <pre><code>      var button = UIButton()
        var x = 0
        let buttonTags = [0,1,2,3,4]
        if choices.count == 2 {
          for idx in buttonTags {
              button = surveyChoices[idx]
              if idx &lt; choices.count {
              button.setTitle(choices[x], for: .normal)
              x += 1
              } else {
                  button.isHidden = true
              }
          }
      }
  </code></pre>