title: Working with NSData in swift
body: <p>So I've figured out how to extract NSData in swift but i'm getting confused with regards to setting it:</p>
  
  <pre><code>var testBytes : [Byte] = [0x14, 0x00, 0xAB, 0x45, 0x49, 0x1F, 0xEF, 0x15,     
                            0xA8, 0x89, 0x78, 0x0F, 0x09, 0xA9, 0x07, 0xB0,
                            0x01, 0x20, 0x01, 0x4E, 0x38, 0x32, 0x35, 0x56,
                            0x20, 0x20, 0x20, 0x00]
  
  var msgData = NSData(bytes: testBytes, length: testBytes.count)
  
  println("\(msgData)")
  
  
  var length : Int = testBytes.count
  
  var out: NSInteger = 0
  
  let ptr = UnsafePointer&lt;UInt8&gt;(msgData.bytes)
  var bytes = UnsafeBufferPointer&lt;UInt8&gt;(start: ptr, count: 28)
  </code></pre>
  
  <p>So if i want to access a specific byte I can get it with something like:</p>
  
  <pre><code>let targetAddress = UInt32(bytes[2]) &lt;&lt; 16 |
      UInt32(bytes[3]) &lt;&lt; 8 |
      UInt32(bytes[4]) &lt;&lt; 0
  </code></pre>
  
  <p>Now say I wanted to set a value with something like:</p>
  
  <pre><code>bytes[11] = UInt8(UInt32(bytes[11]) | 0x0FF)
  </code></pre>
  
  <p>I get an error of <code>Cannot assign the result of this expression)</code>.  I tried also using <code>&amp;bytes[11]</code> which doesn't seem to fly either.</p>
  
  <p>I'm assuming this is because the array uses an unsafe buffer pointer.  Is there an easy call that I've some how glossed over to make the assignment work correctly?</p>