Will writeToFile: atomically: overwrite data?

A really simple question, but it doesn't seem explicit in Apple docs.

Will writeToFile:atomically: for NSData , NSArray , etc. overwrite existing data in a file?

+81
ios objective-c
Oct 20 2018-11-11T00:
source share
2 answers

Yes. This will.

Here are some characters to convey a 30 character limit.

+182
Oct. 20 '11 at 0:59
source share

Method writeToFile:atomically: ALWAYS VIOLATE A FILE , regardless of atomically: YES or NO.

Information from Apple Docs (NSData, Saving Data):

The NSData class and its subclasses provide methods for quickly and easily saving their contents to disk. To minimize the risk of data loss, these methods provide the ability to save data atomically. Atomic writes that the data is either saved completely, or it fails completely. Atomic recording begins by writing data to a temporary file. If this record succeeds, then the method moves the temporary file to its final location.

There is not a single word about checking for a file.

For example, for the copyItemAtPath:toPath:error: method in docs (NSFileManager, Discussion section), specifically written about such a check:

If a file with the same name already exists in dstPath, this method stops the copy attempt and returns the corresponding error.

+3
Jan 17 '17 at 20:28
source share



All Articles