title: Make use of Prize Enum and extension in Swift
body: <p>Using <a href="http://online.swiftplayground.run/" rel="nofollow noreferrer">http://online.swiftplayground.run/</a> - this was my original implementation:</p>
  
  <pre><code>import Foundation
  
  let IPHONE = "iphone"
  let IPAD = "ipad"
  let MACBOOK = "macbook"
  let IMAC = "imac"
  let NOTHING = "nothing"
  
  let prizes: [String] = [IPHONE, IPAD, MACBOOK, IMAC, NOTHING];
  
  func pickRandomPrize(prizes: Array&lt;String&gt;) -&gt; String {
      let randomPrize: String = prizes.randomElement()!
      return randomPrize
  }
  
  class PrizeAnnouncer {
      let prizeWon: String;
      init(prizeWon: String) {
          self.prizeWon = prizeWon
      }
      func announce() {
          if prizeWon == NOTHING {
              return print("You've won... nothing")
          }
  
          print("Congratulations! You've won an \(prizeWon)")
      }
  }
  
  let randomPrize = pickRandomPrize(prizes: prizes)
  let announcer = PrizeAnnouncer(prizeWon: randomPrize)
  announcer.announce()
  </code></pre>
  
  <p>I did a different version leveraging Enums below.</p>
  
  <pre><code>import Foundation
  
  enum Prize: String, CaseIterable {
    case iphone
    case ipad
    case macbook
    case imac
    case nothing
  }
  
  let prizes: [Prize] = Prize.allCases
  
  func pickRandomPrize(prizes: [Prize]) -&gt; Prize {
      let randomPrize: Prize = prizes.randomElement()!
      return randomPrize
  }
  
  class PrizeAnnouncer {
      let prizeWon: Prize;
      init(prizeWon: Prize) {
          self.prizeWon = prizeWon
      }
      func announce() {
          if prizeWon == Prize.nothing {
              return print("You've won... nothing")
          }
  
          print("Congratulations! You've won an \(prizeWon)")
      }
  }
  
  let randomPrize = pickRandomPrize(prizes: prizes)
  let announcer = PrizeAnnouncer(prizeWon: randomPrize)
  announcer.announce()
  </code></pre>
  
  <p>I am using this as a chapter of a book that introduces people interested in software engineering - and Swift is one of those considerations.</p>
  
  <p>Each chapter has the following sections and uses code examples of the standard library:</p>
  
  <ul>
  <li>Language introduction</li>
  <li>Code example</li>
  <li>Use cases</li>
  <li>Did you know</li>
  </ul>