Error The operation couldn’t be completed. (Cocoa error 516.)
2013-11-21 19:29
1386 查看
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
toPath:destSpecFile
error:&err];
Before attempting the copyItemAtPath, check the destination file and if there, remove it.
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
toPath:destSpecFile
error:&err];
Before attempting the copyItemAtPath, check the destination file and if there, remove it.
相关文章推荐
- The operation couldn’t be completed. (Cocoa error 513.)
- The operation couldn't be completed.(Cocoa error 256)
- Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)
- iOS模拟器URLWithString The operation couldn't be completed. (Cocoa error 256.)
- Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)"
- The operation couldn’t be completed. (Cocoa error 4.)
- NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)"
- Xcode5+svn迁出项目出现“The operation couldn’t be completed. (NSURLErrorDomain error -1012.)”的解决方案
- Xcode 5 解决 The operation couldn’t be completed. (NSURLErrorDomain error 0.) 问题
- The operation couldn’t be completed. (LaunchServicesError error 0.)
- 【解决方法】Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed.
- Unable to run the Simulator The operation couldn’t be completed. (LaunchServicesError error 0.)
- xcode The operation couldn’t be completed. (LaunchServicesError error 0.) 模拟器错误解决
- The operation couldn't be completed (LaunchServicesError error 0.)
- The operation couldn’t be completed. (FBSOpenApplicationErrorDomain error 3.)
- The operation couldn’t be completed. (LaunchServicesError error 0.)问题
- [iOS]The operation couldn’t be completed. (LaunchServicesError error 0.)
- The operation couldn’t be completed. (LaunchServicesError error 0.)
- 解决The operation couldn’t be completed. (LaunchServicesError error 0.)
- MonkeyKing canOpenURL: failed for URL: "weixin://" - error: "The operation couldn’t be completed. (O