I did what I did not want to do, and threw this dumb search approach. It works, although it is terrible, slow and gives me memory problems when the photo library is large.
As a noob for both Cocoa and Swift, I would appreciate clarification tips. Thanks!
func PHAssetForFileURL(url: NSURL) -> PHAsset? { var imageRequestOptions = PHImageRequestOptions() imageRequestOptions.version = .Current imageRequestOptions.deliveryMode = .FastFormat imageRequestOptions.resizeMode = .Fast imageRequestOptions.synchronous = true let fetchResult = PHAsset.fetchAssetsWithOptions(nil) for var index = 0; index < fetchResult.count; index++ { if let asset = fetchResult[index] as? PHAsset { var found = false PHImageManager.defaultManager().requestImageDataForAsset(asset, options: imageRequestOptions) { (_, _, _, info) in if let urlkey = info["PHImageFileURLKey"] as? NSURL { if urlkey.absoluteString! == url.absoluteString! { found = true } } } if (found) { return asset } } } return nil }
source share