title: How do i convert HexString To ByteArray in Swift 3
body: <p>I'm was trying to convert hexString to Array of Bytes([UInt8]) I searched everywhere but couldn't find a solution. Below is my swift 2 code </p>
  
  <pre><code>func stringToBytes(_ string: String) -&gt; [UInt8]? {
      let chars = Array(string)
      let length = chars.count
      if length &amp; 1 != 0 {
          return nil
      }
      var bytes = [UInt8]()
      bytes.reserveCapacity(length/2)
      for var i = 0; i &lt; length; i += 2 {
          if let a = find(hexChars, chars[i]),
              let b = find(hexChars, chars[i+1]) {
              bytes.append(UInt8(a &lt;&lt; 4) + UInt8(b))
          } else {
              return nil
          }
      }
      return bytes
  } 
  </code></pre>
  
  <p><strong>Example Hex</strong> </p>
  
  <p>Hex : "7661706f72"</p>
  
  <p>expectedOutput : "vapor"</p>