title: The file couldn't be opened because there is no such file when getting FileAttributesKey - Swift
body: <p>I am trying to get the FileAttributesKey using FileManager in iOS using Swift. When I try that, I am getting the following error&quot;</p>
  <pre><code>Error Domain=NSCocoaErrorDomain Code=260 &quot;The file “Personal%20Narrative%20Essay.txt” couldn’t be opened because there is no such file.&quot; UserInfo={NSFilePath=file:///private/var/mobile/Library/Mobile%20Documents/com~apple~TextEdit/Documents/Personal%20Narrative%20Essay.txt, NSUnderlyingError=0x283e720a0 {Error Domain=NSPOSIXErrorDomain Code=2 &quot;No such file or directory&quot;}}
  </code></pre>
  <p>It says that the file doesn't exist but I know that it does exist because it is appearing in the UIDocumentPicker and I am able to get the contents of the file using <code>try! Data(contentsOf: URL)</code>.</p>
  <p>My code for getting the attributes of the file is:</p>
  <pre><code>func processURL(url: URL) -&gt; Bool {
          let newPath = url.absoluteString
          print(newPath)
          do {
              let attributes = try FileManager.default.attributesOfItem(atPath: newPath)
              let fileSize = attributes[FileAttributeKey.size]
              print(&quot;Calculated File Size: \(fileSize!)&quot;)
              return true
          }
          catch {
              print(error)
              self.isShowingSpinner = false
              self.isShowingURLErrorAlert = true
              return false
          }
          return true
      }
  </code></pre>
  <p>I just need to be able to get the file size for now which I am doing using the above function. I do not understand if I am doing something wrong. Thanks in advance for the help.</p>