I'm trying to get a UIImage Object from a given Asset-Library-Url. I want to make function doing this for me.
The given Url is: assets-library://asset/asset.JPG?id=46811D66-DBB4-46D9-BBA2-0CF0D58FC7AD&ext=JPG
I tried it with the following approach :
var url = NSURL() // url = "assets-library://asset/asset.JPG?id=46811D66-DBB4-46D9-BBA2-0CF0D58FC7AD&ext=JPG" got it from another scene
var asset = ALAssetsLibrary()
var tempImage = UIImage()
tempImage = getUIImagefromAsseturl(url)
func getUIImagefromAsseturl (url: NSURL) -> UIImage {
asset.assetForURL(url, resultBlock: {
(asset: ALAsset!) in
if asset != nil {
var assetRep: ALAssetRepresentation = asset.defaultRepresentation()
var iref = assetRep.fullResolutionImage().takeUnretainedValue()
var image = UIImage(CGImage: iref)
return image
}
}, failureBlock: {
(error: NSError!) in
NSLog("Error!", nil)
}
)
}
But I always get an error saying that : Cannot invoke 'assetForURL' with an argument list of type '(NSURL, resultBlock: (ALAsset!) -> _, failureBlock: (NSError!) -> _)'
Can anybody please tell me what i'm doing wrong here?