Created
May 15, 2018 17:03
-
-
Save zwaldowski/4c1a604b510b441138891891af327ec8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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