My app crashes with error Thread 1: EXC_BAD_INSTRUCTION when this method is called:
imageManager.requestImage(for: asset!, targetSize: CGSize(width:100,height:100), contentMode: .aspectFit, options: options, resultHandler: {(image,info) -> Void in})
Full code in view did load:
override func viewDidLoad() {
super.viewDidLoad()
collectionView.delegate = self;
collectionView.dataSource = self;
let fetchResult = PHAsset.fetchAssets(with: PHAssetMediaType.image, options: nil);
let asset = fetchResult.firstObject;
let options = PHImageRequestOptions()
options.deliveryMode = .fastFormat
options.isSynchronous = true
let imageManager = PHCachingImageManager();
imageManager.requestImage(for: asset!, targetSize: CGSize(width:100,height:100), contentMode: .aspectFit, options: options, resultHandler: {(image,info) -> Void in
print("Got image")
})
}
Anyone know what might be causing the error? I think it has something to do with the closure but I'm not sure what is wrong...
here is the method syntax which I am trying to call:
func requestImage(for asset: PHAsset, targetSize: CGSize, contentMode: PHImageContentMode, options: PHImageRequestOptions?, resultHandler: (UIImage?, [NSObject : AnyObject]?) -> Void) -> PHImageRequestID
Thanks!