title: Objective-C - How can I convert Byte Array to NSString?
body: <p>I am trying to convert a byte array into a <code>NSString</code> object. For testing purposes I am then just trying to print out the contents of the string to the log. </p>
  
  <p>Here's what I got:</p>
  
  <pre><code>UInt8 buf[BUFSIZE];
  CFIndex bytesRead = CFReadStreamRead(stream, buf, BUFSIZE);
  if (bytesRead &gt; 0) {
  NSString  *serverText = [[NSString alloc] initWithBytes:buf
                                                   length:(NSUInteger)BUFSIZE
                                                 encoding:NSASCIIStringEncoding];
  NSLog("%@",serverText);
  [serverText release];
  </code></pre>
  
  <p>I am trying to initialize a new <code>NSString</code> using <code>initWithBytes</code> and store this in <code>serverText</code>. I can see in the debugger that the value of <code>serverText</code> is "invalid address". I am new to objective-c but I assume that means the <code>initWithBytes</code> factory method was not successful.</p>
  
  <p>The buffer contains data. Can someone help me out?</p>
  
  <p>Thanks.. </p>