Skip to content

Instantly share code, notes, and snippets.

@woxtu
Created November 3, 2023 11:33
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 woxtu/7bff7d1338fa9ca3ec5744569e4262f8 to your computer and use it in GitHub Desktop.
Save woxtu/7bff7d1338fa9ca3ec5744569e4262f8 to your computer and use it in GitHub Desktop.
async UIImageWriteToSavedPhotosAlbum(_:_:_:_:)
private final class UIImageWriteToSavedPhotosAlbumCompletion: NSObject {
var continuation: CheckedContinuation<Void, any Error>?
@objc func image(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) {
if let error {
continuation?.resume(throwing: error)
} else {
continuation?.resume()
}
continuation = nil
}
}
func UIImageWriteToSavedPhotosAlbum(_ image: UIImage) async throws {
let completion = UIImageWriteToSavedPhotosAlbumCompletion()
return try await withCheckedThrowingContinuation { continuation in
completion.continuation = continuation
UIImageWriteToSavedPhotosAlbum(
image,
completion,
#selector(UIImageWriteToSavedPhotosAlbumCompletion.image(_:didFinishSavingWithError:contextInfo:)),
nil
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment