Requesting an image with Swift 3 results in "Creating an image format with an unknown type is an error"

I have a controller in which I simply extract the images in the user's gallery and display them. It was used to work with Xcode 7.3, but after updating it to Xcode 8.0 and updating the code for Swift 3.0 compatibility, this gives me a strange and very general error:

Creating an image format with an unknown type is a mistake

I can’t understand what is not working here. My code is as follows:

let imgManager = PHImageManager.default() let requestOptions = PHImageRequestOptions() requestOptions.isSynchronous = false requestOptions.deliveryMode = PHImageRequestOptionsDeliveryMode.fastFormat let fetchOptions = PHFetchOptions() fetchOptions.sortDescriptors = [NSSortDescriptor(key:"creationDate", ascending: false)] let fetchResult = PHAsset.fetchAssets(with: PHAssetMediaType.image, options: fetchOptions) if fetchResult.count > 0 { for i in 0...(fetchResult.count-1) { imgManager.requestImage(for: fetchResult.object(at: i), targetSize: view.frame.size, contentMode: PHImageContentMode.aspectFit, options: requestOptions, resultHandler: { (image, _) in // do some stuff self.progressView.isHidden = true }) } } else { self.progressView.isHidden = true } 

In this code, I removed the image rendering code for readability. The instruction that triggers the error is "requestImage". Any help would be greatly appreciated.

+6
source share

All Articles