title: Write a file on iOS
body: <p>How do I write a file on iOS? I'm trying to do it with the following code but I'm doing something wrong:</p>
  
  <pre><code>char *saves = "abcd";
  NSData *data = [[NSData alloc] initWithBytes:saves length:4]; 
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  NSString *documentsDirectory = [paths objectAtIndex:0];
  NSString *appFile = [documentsDirectory stringByAppendingPathComponent:@"MyFile"];
  [data writeToFile:appFile atomically:YES];
  </code></pre>
  
  <p>I have created MyFile.txt on resources.</p>