Save NSData always to the same file

cocoa-touch, ios, nsdata, objective-c

Solution

Get the file.

Remove it from `NSTemporaryDirectory`.

[[NSFileManager defaultManager] removeItemAtPath:filePath error:&error];

Create a new file with same name and save it there.

[[NSData data] writeToFile:filePath options:NSDataWritingAtomic error:nil];

Or Simply you can over-write the file.

NSData *data = <all data>;
[data writeToFile:targetPath atomically:YES];

Problem

I want to save each `NSData` object to a temp directory in iOS and I want each new object to overwrite the old one. Objects will be of different formats and of different sizes. I know how do you get the path to the `NSTemporaryDirectory` but how on Earth can you overwrite old `NSData` file in there each time a new one is added?

Original source

Related problems