There appears to be a data loss bug in NSFileWrapper on macOS 26.4. It may have been around longer but I just never noticed ...
So I write a RTFD file wrapper:
NSFileWrapper *rtfd = [attributedString RTFDFileWrapperFromRange:NSMakeRange(0, attributedString.length) documentAttributes:@{NSDocumentTypeDocumentAttribute:NSRTFDTextDocumentType}];
Now IF I use -writeToURL:options:originalContentsURL:error: without using the NSFileWrapperWritingAtomic option and I pass in an existing URL, the followings happens:
-The method returns NO and populates the NSError with NSFileWriteFileExistsError, as expected. This is what I want.
-BUT the existing file is nuked. It just disappears. Foundation kills it. Poof.
Another thing I gotta workaround. Getting pretty ridiculous, I must say. Just my lucky day I guess. It would be wonderful if I could work on my own features and fixing my own bugs.
I wouldn’t characterise this as a bug. If you set the atomic flag then the file wrapper will either work or, if something goes wrong, leave the destination unchanged. The system has to jump through extra hoops to provide this guarantee.
OTOH, if you don’t set that flag then you’re telling the system that you don’t care about the state destination in the error case. The system is free to choose whatever writing techniques that it finds convenient. This is a valid choice if, for example, you’re writing to a temporary file, but it doesn’t look like that’s the case for you.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"