Check if image exists in Photos
<p>I have an album of images that is managed by a remote server. I would like to give the user an option to download the album and store it to a custom album in Photos. But since the album is dynamic (photos get added to it) the user can download it multiple times. I don't want to download the same pictures multiple times, only the new ones.</p>

<p>Is it possible to associate some metadata (unique id) when I store the image in the Photo app? And then check if that image already exists? </p>

<p>I am using the Photos Framework to create the custom album and save the photos.</p>

<p>Edit: Here is my code for creating the custom album and saving photos</p>

<pre><code>/** Returns the first album from the photos app with the specified name. */
static func getAlbumWithName(name: String, completion: (album: PHAssetCollection?) -&gt; Void) {

    let fetchOptions = PHFetchOptions()
    fetchOptions.predicate = NSPredicate(format: "localizedTitle = %@", name)
    let fetchResult = PHAssetCollection.fetchAssetCollectionsWithType(PHAssetCollectionType.Album, subtype: PHAssetCollectionSubtype.Any, options: fetchOptions)

    if fetchResult.count &gt; 0 {

        guard let album = fetchResult.firstObject as? PHAssetCollection else {return}
        completion(album: album)

    } else {

        PHPhotoLibrary.sharedPhotoLibrary().performChanges({

            PHAssetCollectionChangeRequest.creationRequestForAssetCollectionWithTitle(name)

            }, completionHandler: { (result, error) in

                if result {

                    FileUtils.getAlbumWithName(name, completion: completion)

                } else {

                    completion(album: nil)

                }


        })

    }

}

/** Adds an image to the specified photos app album */
private static func addImage(image: UIImage, toAlbum album: PHAssetCollection, completion: ((status: Bool) -&gt; Void)?) {

    PHPhotoLibrary.sharedPhotoLibrary().performChanges({

        let assetRequest = PHAssetChangeRequest.creationRequestForAssetFromImage(image)
        let assetPlaceholder = assetRequest.placeholderForCreatedAsset
        let albumChangeRequest = PHAssetCollectionChangeRequest(forAssetCollection: album)
        albumChangeRequest?.addAssets([assetPlaceholder!])


    }) { (status, error) in

        completion?(status: status)

    }

}
</code></pre>