Breaking News
Home / iOS / iOS Isuses / Error The operation couldn’t be completed. (Cocoa error 516.)

Error The operation couldn’t be completed. (Cocoa error 516.)


This is very common error that happens when you try to create a file on the file system and a file with the same name already exists. You can avoid that by checking whether a file with the name already exists or not. If it does exists then remove it and try to create again.

Error 516 is NSFileWriteFileExistsError – You can’t move a file to a place where a file already exists.

The below code does not check for this and can lead to above error:

            NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
            NSString *destSpecFile = [NSString stringWithFormat:@”%@/%@”, docDir,gallerySpecFile];
            NSError *err;
            NSString *srcPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:gallerySpecFile];
            CCLOG(@”Src %@”,srcPath);
            CCLOG(@”Descr %@”,destSpecFile);
            [[NSFileManager defaultManager] copyItemAtPath:srcPath

Before attempting the copyItemAtPath, check the destination file and if there, remove it.



Check Also

Signing Identities, Missing Private Key, Cannot sign App

Issue Cannot sign the App in XCode, says Missing Private Key. <!

Advertisment ad adsense adlogger