What is the best way to load image for UIImage in resultBlock of ALAssetLibray?

41 Views Asked by At

I am trying to load image for UIImage in resultBlock of ALAssetLibray. it works, but sometime i got EXC_BAD_ACCESS in the resultBlock. i guess it is around asynchronous-problems... now i can't understand the best way to load image. my code in the following. anyone know what's wrong.

func loadImage(url: String!) {

    let asseturl = URL(string: url)!

    self.assetsLibrary.asset(
        for: asseturl,
        resultBlock: { (asset:ALAsset?) -> Void in

            print("ok")
            let cgi = asset!.thumbnail()
            let img = UIImage(cgImage: cgi!.takeRetainedValue()
            self.image = img // EXC_BAD_ACCESS here

        },                
        failureBlock: { (error: Error?) -> Void in

        }       
    )


}
0

There are 0 best solutions below