Skip to content

Instantly share code, notes, and snippets.

@grimabe
Last active November 8, 2017 09:10
Show Gist options
  • Save grimabe/7bf59478fa739fcca308cd0fe04e6bef to your computer and use it in GitHub Desktop.
Save grimabe/7bf59478fa739fcca308cd0fe04e6bef to your computer and use it in GitHub Desktop.
import Photos
class AssetsHelper {
class func addAsset(image: UIImage, completion: @escaping (_ identifier: String?) -> Void) {
var identifier: String?
PHPhotoLibrary.shared().performChanges({
let request = PHAssetChangeRequest.creationRequestForAsset(from: image)
identifier = request.placeholderForCreatedAsset?.localIdentifier
}) { success, error in
guard success == true,
let identifier = identifier else {
completion(nil)
return
}
completion(identifier)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment