title: Objective C: Write a file programmatically to the Main Bundle
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/5853014/writing-into-a-file-objective-c">Writing into a file objective c</a>  </p>
  </blockquote>
  
  
  
  <p>How do I create and write a file to the bundle? I have this:</p>
  
  <pre><code>//make path to file
  NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,    NSUserDomainMask, YES) objectAtIndex:0];
  NSString *filePath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"usnews.txt", [sharedManager.articleNumber intValue] + 1]];
  //write file
  [textContent writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:nil];
  </code></pre>
  
  <p>but it writes it to the documents folder and is deleted when the app is closed. </p>