Search code examples
objective-ccocoaerror-handlingcopynsfilemanager

cocoa properly copy file


I want to implement a simple file save, currently I am using writeToUrl :options :error method of NSData, it does the job, but I want to know what is the proper way to do so ?

I mean if file with the same name is already exists and I need to ask user for additional input, failed to copy and things like that.

Is there something built in cocoa framework that takes care of that ? I took a look at NSFileManager but I can't see things like that there ?

I am sorry if this question is very noobish , but I never touched file system except user defaults before, and can't find desired methods.


Solution

  • Yes, you will have to write your own error handling code. Checking if the file already exists, telling the user, prompting for a new name. All these things are developer code.