title: Objective-C creating a text file with a string
body: <p>I'm trying to create a text file with the contents of a string to my desktop. I'm not sure if I'm doing it right, I don't get errors but it doesn't work either...</p>
  
  <pre><code>NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES);
  NSString *desktopDirectory=[paths objectAtIndex:0];
  NSString *filename = [desktopDirectory stringByAppendingString: @"file.txt"];
  [myString writeToFile:filename atomically:YES encoding: NSUTF8StringEncoding error: NULL];
  </code></pre>