SWIFT:尝试从库中获取所有图像时崩溃

时间:2018-04-09 20:11:13

标签: swift xcode

当我尝试从库中获取所有图像时,应用程序不断崩溃,来自调试器的消息是:由于内存问题而终止

任何想法如何解决它?这是我的代码:

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

            }
        }
        )
    }
}

0 个答案:

没有答案