4

In my code I'm doing:

[anNsDataObject writeToFile:@"thefile" atomically:YES];

How can I delete this file from my device?

Evan Mulawski
  • 54,662
  • 15
  • 117
  • 144
Jacksonkr
  • 31,583
  • 39
  • 180
  • 284

1 Answers1

13

Using NSFileManager's removeItemAtPath:error: method.

Example:

NSError *error;
[[NSFileManager defaultManager]removeItemAtPath:@"theFile" error:&error];

if (error)
{
  // file deletion failed
}
Evan Mulawski
  • 54,662
  • 15
  • 117
  • 144
  • Is there a way to ensure ```removeItemAtPath``` happens synchronously? I have read that ```NSFileManager``` may or may not delete the file depending on data storage and other factors. – Supertecnoboff Jul 25 '16 at 12:42