title: Working Directory in Objective-C and Xcode: debug mode vs. executable
body: <p>I am writing a program in Objective-C using Xcode. My program creates a file as follows:</p>
  
  <pre><code>[@"" writeToFile:fileName atomically:YES encoding:NSUTF8StringEncoding error:NULL];
  </code></pre>
  
  <p>I would like the file to be created in the same directory as the executable. When I run the program from Xcode, the file is created in the debug directory as expected.</p>
  
  <p>However, when I run the .app file, the file is created in the root directory. How can I get the program to create a file in the directory where the .app file is located.</p>
  
  <p>Thanks a lot.</p>
  
  <p>EDIT: This is a MacOS application</p>
  
  <p>EDIT2: Well, it seems that I shouldn't be writing to the .app directory. Thanks bbum and Paul R. What is the proper way to do it? To be more concrete, here's what I am doing: each time the user clicks a button in the application, a piece of hardware connected to a serial port will send a bunch data which will be written to a new file. This can happen any number of times while the application is running, so numerous files may be created. I would like them all created in the same folder.</p>