title: Read Content Of File from iCloud
body: <p>I have successfully got the list of files stored in iCloud drive. When I check the file exists at the path, it returns true.</p>
  
  <p>But when I try to get the content of a file, it's not allowing me to read the file and providing some garbage data. </p>
  
  <p>Can I read the file from iCloud directly or needs to move it to app's documents folder first?
  Thanks in advance for your help.</p>
  
  <p>Here is my code</p>
  
  <p><strong>iCloud URL</strong></p>
  
  <pre><code>static let iCloudDocumentsURL: URL? = FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Documents")
  </code></pre>
  
  <p><strong>File Path</strong></p>
  
  <pre><code>let filePath =DocumentsDirectory.iCloudDocumentsURL?.appendingPathComponent(file).path
  </code></pre>
  
  <p><strong>Checking File exists and its showing "File Available"</strong></p>
  
  <pre><code>if FileManager().fileExists(atPath: filePath)
          {
              print("File Available")
          }
          else
          {
              print("Not Available")
          }
  </code></pre>
  
  <p>Getting data of file and it showing <strong>176</strong> bytes which is actually <strong>76756</strong> bytes</p>
  
  <pre><code>let fileData = NSData.init(contentsOfFile: filePath)
  </code></pre>