当我尝试从库中获取所有图像时,应用程序不断崩溃,来自调试器的消息是:由于内存问题而终止
任何想法如何解决它?这是我的代码:
func fetchImagesFromLibrary() {
let fetchOptions: PHFetchOptions = PHFetchOptions()
fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
let fetchResult = PHAsset.fetchAssets(with: .image, options: fetchOptions)
fetchResult.enumerateObjects { (object, index, stop) -> Void in
let options = PHImageRequestOptions()
options.isSynchronous = false
options.deliveryMode = .fastFormat
PHImageManager.default().requestImage(for: fetchResult.object(at: index) as PHAsset, targetSize: self.view.frame.size, contentMode: PHImageContentMode.aspectFill, options: .none, resultHandler: { (image, _) in
if let image = image {
print(image)
//self.imageview1.image = image
}
}
)
}
}