Created
November 3, 2023 11:33
-
-
Save woxtu/7bff7d1338fa9ca3ec5744569e4262f8 to your computer and use it in GitHub Desktop.
async UIImageWriteToSavedPhotosAlbum(_:_:_:_:)
This file contains hidden or 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
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