Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacing NSFileWrappers

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

So far I've used this code:

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

However, whenever the FileWraper already exists, I get duplicates in my FileWrapper which look so:

"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 simply replace the FileWrapper - in this case photo.data? I did not find any method to replace FileWrappers in the NSFileWrapper Class Reference.

like image 974
n.evermind Avatar asked Jun 20 '12 15:06

n.evermind


1 Answers

I think this may be the solution:

NSFileWrapper *oldFileWrapper = [self.fileWrapper.fileWrappers objectForKey:fileName];
if (oldFileWrapper) [self.fileWrapper removeFileWrapper:oldFileWrapper];

[self.fileWrapper addRegularFileWithContents:[self encodeObject:object] 
                           preferredFilename:fileName];
like image 71
n.evermind Avatar answered Oct 23 '22 14:10

n.evermind