title: Fetching images from Document Directory
body: <p>Hi guys I want to fetch all images from document and append them in cell.</p>
  
  <p>I created this function to save images on didSelectItemAt</p>
  
  <pre><code> func saveImage(image: UIImage, imageName: String) {
  
      let path = "yourProjectImages"
         let document = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.appendingPathComponent(path, isDirectory: true)
  
  
  
          let imageUrl = document!.appendingPathComponent("\(imageName).jpg", isDirectory: true)
  
          do {
  
                  try UIImagePNGRepresentation(image)?.write(to: imageUrl, options: .atomic)
              } catch {
  
              print(error.localizedDescription)
  
  
              }
  
          }
  </code></pre>
  
  <p>I used it as I said in didSelectItemAt</p>
  
  <pre><code>    override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  
  
  let selectedImage = images[indexPath.item]
  
  saveImage(image: selectedImage, imageName: "\(selectedImage)")
  
  
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/ylsf4.png" rel="nofollow noreferrer">it seems to add picture immediately in document after clicking on the picture</a></p>
  
  <p>But how to fetch them all in HomeFeed which is my rootController?</p>
  
  <p>These showed photos is album I used Photos framework to fetch multiple photos from album.</p>