title: Unable to save file to local storage in ios swift
body: <p>I am trying to download file content from server, creating one file on client end and tranfering all content to that. I am saving the file to local storage,but it is unable to save throws exception that you don't have permission to save in folder. Tried so many things but unable to do so. I am very new to this ios programming. Please help me out, thanks in advance.</p>
  
  <p>Below is my code:</p>
  
  <pre><code> let documentsUrl =  FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first
   var fileURL : URL = URL(fileURLWithPath: documentsUrl!.path+filename)
    fileURL = URL(fileURLWithPath: documentsUrl!.path+filename+".doc")
    let data = NSData(contentsOf: tempLocalUrl)
                  do {
                      try data?.write(to: fileURL, options: .atomic)
                  } catch {
                      print(error,"helooooooooooooooooo")
                  }
  </code></pre>
  
  <p>I have used relativepath, absolutestring but still no luck .</p>
  
  <p>This is the error :</p>
  
  <blockquote>
    <p>Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file “DocumentsImport From IE.doc” in the folder “0103E60B-478F-475B-A8F2-788534F5D206”." UserInfo={NSFilePath=/var/mobile/Containers/Data/Application/0103E60B-478F-475B-A8F2-788534F5D206/DocumentsImport From IE.doc, NSUnderlyingError=0x1076efe90 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}</p>
  </blockquote>