title: Swift - How get photo albums with all photos include iCloud Library?
body: <p>I need get all photo albums from device. I use this code for fetch albums:</p>
  
  <pre><code>func fetchAlbums() {
         // Get all user albums 
          let userAlbumsOptions = PHFetchOptions()
          userAlbumsOptions.predicate = NSPredicate(format: "estimatedAssetCount &gt; 0")
  
  
          let userAlbums = PHAssetCollection.fetchAssetCollections(with: PHAssetCollectionType.album, subtype: PHAssetCollectionSubtype.any, options: userAlbumsOptions)
  
          userAlbums.enumerateObjects( {
              if let collection = $0.0 as? PHAssetCollection {
                  print("album title: \(collection.localizedTitle)")
  
                  let onlyImagesOptions = PHFetchOptions()
                  onlyImagesOptions.predicate = NSPredicate(format: "mediaType = %i", PHAssetMediaType.image.rawValue)
  
                  if let result = PHAsset.fetchKeyAssets(in: collection, options: onlyImagesOptions) {
                      print("Images count: \(result.count)")
                      if result.count &gt; 0  {
                          //Add album titie
                          self.albumsTitles.append(collection.localizedTitle!)
                          //Add album
                          self.albumsArray.append(result as! PHFetchResult&lt;AnyObject&gt;)
                    }
                  }
              }
          } )
  
  
      }
  </code></pre>
  
  <p>But i can't get all photos. All albums without photos from iCloud library, only local photos. 
  I use Collection View for preview photo. Example my code for fetch photos from selected album:</p>
  
  <pre><code>    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
  
          let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: AlbumPhotoCollectionViewCell.self), 
                                    for: indexPath as IndexPath) as! AlbumPhotoCollectionViewCell
  
                      //Array with albums
                      let asset = self.albumsArray[indexSelectedAlbum]
  
                      let album = asset[indexPath.item]
  
                      let options = PHImageRequestOptions()
  
                      options.isNetworkAccessAllowed = true
  
  
                 PHImageManager.default().requestImage(for: album as! PHAsset , 
                                 targetSize: self.assetThumbnailSize,
                                 contentMode: .aspectFill,
                                 options: options, 
                                 resultHandler: {(result, info)in
                                       if result != nil {
  
                                         cell.albumPhoto.image = result
                                }
                      })
  
  
                      return cell
          }
  </code></pre>