title: Sending Hex String using WriteValue in Swift
body: <p>I've been creating an app using XCode and Swift to connect to a bluetooth device (that has a LED colour strip connected to it) and I have written a piece of code that will make it change colour. </p>
  
  <p>Using a bluetooth sniffer, I know that I need to send the value of '52130056FF000000AA' which would make it change to red, in this example. Here's a snippet of the code I have already. Characteristicx is defined before this code.</p>
  
  <pre><code>let data: NSData = "52130056FF000000AA".dataUsingEncoding(NSUTF8StringEncoding)!
  peripheral.writeValue(data, forCharacteristic: characteristicx, type: CBCharacteristicWriteType.WithoutResponse)
  </code></pre>
  
  <p>This code converts the hex string given to this, which I do not want to send.
  '&lt;35323133 30303536 46463030 30303030 4141>'</p>
  
  <p>So, the question is, <strong>How do I get Swift to send just the 52130056FF000000AA to the BLE device and not the converted string?</strong> The issue here is that the writeValue command requires NSData (as far as I can see) and I'm not sure how to use a plain hex string as the data to send in NSData form.</p>
  
  <p>Hope someone can help with this! Any help or even suggestions would be greatly appreciated.</p>