All you have to do is read the "localIdentifier" from the asset placeholder. I added code to return the id to the completion handler. You can deal with these options.
private static func addImage(image: UIImage, toAlbum album: PHAssetCollection, completion: ((status: Bool, identifier: String?) -> Void)?) { var localIdentifier: String? PHPhotoLibrary.sharedPhotoLibrary().performChanges({ let assetRequest = PHAssetChangeRequest.creationRequestForAssetFromImage(image) let assetPlaceholder = assetRequest.placeholderForCreatedAsset let albumChangeRequest = PHAssetCollectionChangeRequest(forAssetCollection: album) albumChangeRequest?.addAssets([assetPlaceholder!]) localIdentifier = assetPlaceholder?.localIdentifier }) { (status, error) in completion?(status: status, identifier: localIdentifier) } }
If you want to read this asset again, your image image method might look something like this (I have not used your legend or variable names). This will read the asset synchronously, but I'm sure you can define an asynchronous option.
internal func loadPhoto(identifier: String) -> UIImage? { if assetCollection == nil { return nil } let fetchOptions = PHFetchOptions() fetchOptions.predicate = NSPredicate(format: "localIdentifier = %@", identifier) let fetchResult = PHAsset.fetchAssetsInAssetCollection(assetCollection, options: fetchOptions) if fetchResult.count > 0 { if let asset = fetchResult.firstObject as? PHAsset { let options = PHImageRequestOptions() options.deliveryMode = .HighQualityFormat options.synchronous = true var result: UIImage? PHImageManager.defaultManager().requestImageForAsset(asset, targetSize: CGSize(width: asset.pixelWidth, height: asset.pixelHeight), contentMode: .AspectFit, options: options, resultHandler: {(image: UIImage?, _: [NSObject: AnyObject]?) -> Void in result = image }) return result } } return nil }
source share