Skip to content

Instantly share code, notes, and snippets.

@zwaldowski
Created May 15, 2018 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zwaldowski/4c1a604b510b441138891891af327ec8 to your computer and use it in GitHub Desktop.
Save zwaldowski/4c1a604b510b441138891891af327ec8 to your computer and use it in GitHub Desktop.
import Photos
private extension Collection where Element == URLQueryItem {
subscript(_ name: String) -> String? {
return first { $0.name == name }?.value
}
}
extension PHAsset {
static func bbq_fetchAssets(withALAssetURLs assetURLs: [URL], options: PHFetchOptions? = nil) -> PHFetchResult<PHAsset> {
let localIdentifiers = assetURLs.compactMap { (url) -> String? in
// assets-library://asset/asset.jpg?id=42&ext=jpg
guard let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: true),
urlComponents.scheme == "assets-library",
urlComponents.host == "asset" else { return nil }
return urlComponents.queryItems?["id"]
}
return fetchAssets(withLocalIdentifiers: localIdentifiers, options: options)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment