Replacing NSFileWrappers

I have an NSFileWrapper directory in which I would like to update a specific FileWrapper. I was wondering what is the best way to do this?

So far I have used this code:

[self.fileWrapper addRegularFileWithContents:photoData preferredFilename:@"photo.data"]; 

However, whenever FileWraper already exists, I get duplicates in FileWrapper that look like this:

 "1__# $!@ %!#__photo.data" = "<NSFileWrapper: 0x6bb0260>"; "2__# $!@ %!#__photo.data" = "<NSFileWrapper: 0x6b89b80>"; "3__# $!@ %!#__photo.data" = "<NSFileWrapper: 0x6ba1700>"; "4__# $!@ %!#__photo.data" = "<NSFileWrapper: 0x6bc8480>"; "photo.data" = "<NSFileWrapper: 0x6bcfc50>"; 

How can I prevent this and just replace FileWrapper - in this case photo.data? I did not find any way to replace FileWrappers in the NSFileWrapper Class Reference .

+6
source share
2 answers

I think this may be a solution:

 NSFileWrapper *oldFileWrapper = [self.fileWrapper.fileWrappers objectForKey:fileName]; if (oldFileWrapper) [self.fileWrapper removeFileWrapper:oldFileWrapper]; [self.fileWrapper addRegularFileWithContents:[self encodeObject:object] preferredFilename:fileName]; 
+5
source

I just stumbled upon this problem, and for me it was because I had a folder with the name "Resources" and one with the name "Resources" . This created an iCloud problem because on Mac OS X the file system is not case sensitive, but it is on iOS.

It seems that the main problem in your case may also be related to upper / lower case. Of course, you fix this by replacing the file wrapper, which effectively deletes and re-creates the file. This may be an acceptable solution for small files, but can be very inefficient for large or many files in a directory (because the file will be synchronized even if it has not changed).

0
source

Source: https://habr.com/ru/post/918575/


All Articles