“The operation couldn’t be completed. (Cocoa error 512.)”

泪湿孤枕 提交于 2019-11-30 14:22:28

I was able to reproduce your error when writing a file first in the path @"Documents/Images/", then trying to write the image using your code.

I think there are two possible scenarios for this:

1) You created that file by mistake at a previous execution of your app. This will be solved if you reset the simulator using the menu: iOS Simulator > Reset Contents and Settings, and uninstalling the app from your device: Long press > click on the x symbol.

2) There is some code somewhere else in your app that creates this file. If this is the case, you should find this code and remove it.

From FoundationErrors.h:

NSFileWriteUnknownError = 512

Try using withIntermediateDirectories:YES.

In my case a period '.' in the directory name (e.g. ~/Documents/someDir.dir/somefile) was the cause of the problem. I removed the offending character and the error disappeared.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!