title: Error ("'()' is not identical to 'UInt8'") writing NSData bytes to NSOutputStream using the write function in Swift
body: <p>I'm trying to build an asynchronous file download in Swift based on the <a href="https://github.com/erica/iphone-3.0-cookbook-/tree/master/C13-Networking/07-Asynchronous%20Downloads/" rel="nofollow noreferrer">Erica Sadun's method</a>. But I need it to handle bigger files, so I found <a href="https://stackoverflow.com/a/4003076/3877639">this answer about using a NSOutputStream instead of NSData</a>, makes sense.</p>
  
  <p>However, I can't get it to work. I get this error when I try adding the NSData bytes (in my NSURLConnection didReceiveData function) to the NSOutputStream write function: <code>'()' is not identical to 'UInt8'</code> on this row: <code>bytesWritten = self.downloadStream.write(data.bytes, maxLength: bytesLeftToWrite)</code>.</p>
  
  <p><code>data.bytes</code> is of the type <code>ConstUnsafePointer&lt;()&gt;</code> and the <code>.write()</code> function expects the type to be <code>ConstUnsafePointer&lt;UInt8&gt;</code>, so in that sense, the error make perfect sense. But since I'm new to iOS and of course Swift programming, I can't get my head around how to fix this.</p>
  
  <p><strong>So, how do I convert the <code>data.bytes: ConstUnsafePointer&lt;()&gt;</code> to <code>ConstUnsafePointer&lt;UInt8&gt;</code> alt. make this work some other way?</strong></p>
  
  <p><strong>My <code>didReceiveData</code> function:</strong></p>
  
  <pre><code>func connection(connection: NSURLConnection!, didReceiveData data: NSData!) {
  
      var bytesLeftToWrite: NSInteger = data.length
      var bytesWritten: NSInteger = 0
  
      while bytesLeftToWrite &gt; 0 {
  
          bytesWritten = self.downloadStream.write(data.bytes, maxLength: bytesLeftToWrite)
  
          if bytesWritten == -1 {
  
              break
  
          }
  
          bytesLeftToWrite -= bytesWritten
  
          let responseExpectedlenght: NSNumber = NSNumber(longLong: self.downloadResponse!.expectedContentLength)
          let dataLength: NSNumber = NSNumber(long: data.length)
  
          self.downloadProgressPercentage = ((dataLength / responseExpectedlenght) * 100)
  
          println("Downloaded: \(self.downloadProgressPercentage)%")
  
      }
  
  }
  </code></pre>