I'm very green when it comes to Swift, and I'm just trying to get the file URL for a photo I've saved. Below is a small snippet inspired from this StackOverflow question
let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageDataSampleBuffer)
// Save the photo to the album library
let image = UIImage(data: imageData)!
let orientation = ALAssetOrientation(rawValue: image.imageOrientation.rawValue)!
ALAssetsLibrary.writeImageToSavedPhotosAlbum(image.CGImage, orientation: orientation, completionBlock: {
(url: NSURL!, error: NSError!) -> Void in
if error != nil {
print(error)
} else {
// We have the URL here
}
})
However, I can't for the life of me get it to build. It's showing the following error:
Cannot invoke 'writeImageToSavedPhotosAlbum' with an argument list of type '(CGImage?, orientation: ALAssetOrientation, completionBlock: (NSURL!, NSError!) -> Void)'
And it's stating it expects:
Expected an argument list of type '(CGImage!, orientation: ALAssetOrientation, completionBlock: ALAssetsLibraryWriteImageCompletionBlock!)'
The one obvious issue I can see that's off is the CGImage parameter, but I have no clue how to change this, or if that's the only issue. Has anyone seen this or see what my rookie mistake here is?