Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL of image after UIImageWriteToSavedPhotosAlbum in Swift

After i took a photo with the camera i save the image with the following code:

UIImageWriteToSavedPhotosAlbum(image, self,"image:didFinishSavingWithError:contextInfo:", nil)

This saves the image in the camera roll. Additionally i want to save the URL to this saved image in Core Data. Is it possible to retrieve the URL (or the Path) to so that i only need to save this URL and not the full image in Core Data?

like image 468
ManfredP Avatar asked Mar 12 '15 12:03

ManfredP


1 Answers

After reading a lot of answers written in ObjectivC i finally figured out how to write this in Swift with Xcode 6.2:

ALAssetsLibrary().writeImageToSavedPhotosAlbum(image.CGImage, orientation: ALAssetOrientation(rawValue: image.imageOrientation.rawValue)!,
            completionBlock:{ (path:NSURL!, error:NSError!) -> Void in
                println("\(path)")
        })
like image 143
ManfredP Avatar answered Sep 21 '22 17:09

ManfredP