Skip to content

Instantly share code, notes, and snippets.

@FlexMonkey
Last active January 28, 2016 17:35
Show Gist options
  • Save FlexMonkey/d2b1cbd7e1b2caf8d31b to your computer and use it in GitHub Desktop.
Save FlexMonkey/d2b1cbd7e1b2caf8d31b to your computer and use it in GitHub Desktop.
Synchronously create a UIImage from an UIImagePickerControllerReferenceURL
// Could benefit from some defensive coding :)
import Photos
let url = info[UIImagePickerControllerReferenceURL] as! NSURL
let fetchResult = PHAsset.fetchAssetsWithALAssetURLs([url], options: nil)
let asset = fetchResult.firstObject as! PHAsset
let manager = PHImageManager.defaultManager()
let options = PHImageRequestOptions()
options.synchronous = true
options.networkAccessAllowed = true
var image: UIImage?
manager.requestImageForAsset(asset,
targetSize: CGSize(width: 640, height: 640),
contentMode: .AspectFill,
options: options,
resultHandler: {
(imageResult: UIImage?, properties: [NSObject: AnyObject]?) in
image = imageResult
})
print(image)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment