title: What is the typical approach taken for writing NSString objects to a file?
body: <p>As an example, I want to write out some string value, <code>str</code>, to a file, <code>"yy"</code>, as it changes through each iteration of a loop. Below is how I'm currently implementing it: </p>
  
  <pre><code>NSOutputStream *oStream = [[NSOutputStream alloc] initToFileAtPath:@"yy" append:NO];
  [oStream open];
  
  while ( ... )
  {
  
      NSString *str = /* has already been set up */
  
      NSData *strData = [str dataUsingEncoding:NSUTF8StringEncoding];
      [oStream write:r(uint8_t *)[strData bytes] maxLength:[strData length]];
  
      ...
  }
  
  [oStream close];
  </code></pre>
  
  <p>Ignoring the UTF-8 encoding, which I do require, is this how <code>NSString</code>s are typically written to a file? That is, by first converting to an <code>NSData</code> object, then using <code>bytes</code> and casting the result to <code>uint8_t</code> for <code>NSOutputStream</code>'s <code>write</code>?</p>
  
  <p>Are there alternatives that are used more often?</p>
  
  <p>EDIT: Multiple <code>NSString</code>s need to be appended to the same file, hence the loop above.</p>