25 lines
625 B
Swift
25 lines
625 B
Swift
//
|
|
// https://mczachurski.dev
|
|
// Copyright © 2023 Marcin Czachurski and the repository contributors.
|
|
// Licensed under the Apache License 2.0.
|
|
//
|
|
|
|
import Foundation
|
|
import UIKit
|
|
|
|
class ImageSaver: NSObject {
|
|
private let completed: () -> Void
|
|
|
|
init(completed: @escaping () -> Void) {
|
|
self.completed = completed
|
|
}
|
|
|
|
func writeToPhotoAlbum(image: UIImage) {
|
|
UIImageWriteToSavedPhotosAlbum(image, self, #selector(saveCompleted), nil)
|
|
}
|
|
|
|
@objc func saveCompleted(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) {
|
|
self.completed()
|
|
}
|
|
}
|