title: What is the best way to write a switch statement to return an image depending on a number without repeating to much code?
body: <p>I have a switch statement that returns an image based on the case number. I have 8 images of water droplets that start off as an empty droplet(drop_empty) and when the number increases from 1...6 and so on as shown in my code I want to change the images. For the 8 images as shown in the screenshot, I have each one set in an @IBOutlet and in an array in order to choose what image get's assigned to what. I do feel that I'm repeating my self way too much and am hoping to find a better solution to shorten my repetition.
  Hopefully, my code makes more sense.</p>
  <p><a href="https://i.stack.imgur.com/pZk9C.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pZk9C.png" alt="enter image description here" /></a></p>
  <pre><code>    @IBOutlet var waterDropImage1: UIImageView!
      
      @IBOutlet var waterDropImage2: UIImageView!
      
      @IBOutlet var waterDropImage3: UIImageView!
      
      @IBOutlet var waterDropImage4: UIImageView!
      
      @IBOutlet var waterDropImage5: UIImageView!
      
      @IBOutlet var waterDropImage6: UIImageView!
      
      @IBOutlet var waterDropImage7: UIImageView!
      
      @IBOutlet var waterDropImage8: UIImageView!
      
      // Example function name that I would call
      func showDroplets() {
          dropletImageManager(waterPercentage: percentage, droplet: [waterDropImage1, waterDropImage2, waterDropImage3, waterDropImage4, waterDropImage5, waterDropImage6, waterDropImage7, waterDropImage8])
       }
  
      func dropletImageManager(waterPercentage: Int, droplet: [UIImageView]) {
          switch waterPercentage {
          case 0:
              droplet[0].image = UIImage(named: &quot;drop_empty&quot;)
          case 1...6:
              droplet[0].image = UIImage(named: &quot;drop_half&quot;)
          case 7...12:
              droplet[0].image = UIImage(named: &quot;drop_full&quot;)
          case 13...18:
              droplet[0].image = UIImage(named: &quot;drop_full&quot;)
              droplet[1].image = UIImage(named: &quot;drop_half&quot;)
          case 19...25:
              droplet[0].image = UIImage(named: &quot;drop_full&quot;)
              droplet[1].image = UIImage(named: &quot;drop_full&quot;)
          case 26...31:
              droplet[0].image = UIImage(named: &quot;drop_full&quot;)
              droplet[1].image = UIImage(named: &quot;drop_full&quot;)
              droplet[2].image = UIImage(named: &quot;drop_empty&quot;)
          case 32...38:
              droplet[0].image = UIImage(named: &quot;drop_full&quot;)
              droplet[1].image = UIImage(named: &quot;drop_full&quot;)
              droplet[2].image = UIImage(named: &quot;drop_full&quot;)
          case 39...45:
              droplet[0].image = UIImage(named: &quot;drop_full&quot;)
              droplet[1].image = UIImage(named: &quot;drop_full&quot;)
              droplet[2].image = UIImage(named: &quot;drop_full&quot;)
              droplet[3].image = UIImage(named: &quot;drop_half&quot;)
          case 46...52:
              droplet[0].image = UIImage(named: &quot;drop_full&quot;)
              droplet[1].image = UIImage(named: &quot;drop_full&quot;)
              droplet[2].image = UIImage(named: &quot;drop_full&quot;)
              droplet[3].image = UIImage(named: &quot;drop_full&quot;)
              droplet[4].image = UIImage(named: &quot;drop_half&quot;)
          case 53...59:
              droplet[0].image = UIImage(named: &quot;drop_full&quot;)
              droplet[1].image = UIImage(named: &quot;drop_full&quot;)
              droplet[2].image = UIImage(named: &quot;drop_full&quot;)
              droplet[3].image = UIImage(named: &quot;drop_full&quot;)
              droplet[4].image = UIImage(named: &quot;drop_full&quot;)
          case 60...66:
              droplet[0].image = UIImage(named: &quot;drop_full&quot;)
              droplet[1].image = UIImage(named: &quot;drop_full&quot;)
              droplet[2].image = UIImage(named: &quot;drop_full&quot;)
              droplet[3].image = UIImage(named: &quot;drop_full&quot;)
              droplet[4].image = UIImage(named: &quot;drop_full&quot;)
              droplet[5].image = UIImage(named: &quot;drop_half&quot;)
          case 67...73:
              droplet[0].image = UIImage(named: &quot;drop_full&quot;)
              droplet[1].image = UIImage(named: &quot;drop_full&quot;)
              droplet[2].image = UIImage(named: &quot;drop_full&quot;)
              droplet[3].image = UIImage(named: &quot;drop_full&quot;)
              droplet[4].image = UIImage(named: &quot;drop_full&quot;)
              droplet[5].image = UIImage(named: &quot;drop_full&quot;)
          case 74...78:
              droplet[0].image = UIImage(named: &quot;drop_full&quot;)
              droplet[1].image = UIImage(named: &quot;drop_full&quot;)
              droplet[2].image = UIImage(named: &quot;drop_full&quot;)
              droplet[3].image = UIImage(named: &quot;drop_full&quot;)
              droplet[4].image = UIImage(named: &quot;drop_full&quot;)
              droplet[5].image = UIImage(named: &quot;drop_full&quot;)
              droplet[6].image = UIImage(named: &quot;drop_half&quot;)
          case 79...85:
              droplet[0].image = UIImage(named: &quot;drop_full&quot;)
              droplet[1].image = UIImage(named: &quot;drop_full&quot;)
              droplet[2].image = UIImage(named: &quot;drop_full&quot;)
              droplet[3].image = UIImage(named: &quot;drop_full&quot;)
              droplet[4].image = UIImage(named: &quot;drop_full&quot;)
              droplet[5].image = UIImage(named: &quot;drop_full&quot;)
              droplet[6].image = UIImage(named: &quot;drop_full&quot;)
          case 86...92:
              droplet[0].image = UIImage(named: &quot;drop_full&quot;)
              droplet[1].image = UIImage(named: &quot;drop_full&quot;)
              droplet[2].image = UIImage(named: &quot;drop_full&quot;)
              droplet[3].image = UIImage(named: &quot;drop_full&quot;)
              droplet[4].image = UIImage(named: &quot;drop_full&quot;)
              droplet[5].image = UIImage(named: &quot;drop_full&quot;)
              droplet[6].image = UIImage(named: &quot;drop_full&quot;)
              droplet[7].image = UIImage(named: &quot;drop_half&quot;)
          case 93...100:
              droplet[0].image = UIImage(named: &quot;drop_full&quot;)
              droplet[1].image = UIImage(named: &quot;drop_full&quot;)
              droplet[2].image = UIImage(named: &quot;drop_full&quot;)
              droplet[3].image = UIImage(named: &quot;drop_full&quot;)
              droplet[4].image = UIImage(named: &quot;drop_full&quot;)
              droplet[5].image = UIImage(named: &quot;drop_full&quot;)
              droplet[6].image = UIImage(named: &quot;drop_full&quot;)
              droplet[7].image = UIImage(named: &quot;drop_full&quot;)
          default:
              print(&quot;Error&quot;)
          }
  </code></pre>