Created
November 30, 2019 16:04
-
-
Save perlguy99/27ebe96b9b08388a4c77f8c07a812804 to your computer and use it in GitHub Desktop.
Image Saver
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
// ImageSaver.swift | |
// | |
// Created by Brent Michalski on 11/30/19. | |
// Copyright © 2019 Brent Michalski. All rights reserved. | |
// | |
import UIKit | |
class ImageSaver: NSObject { | |
var successHandler: (() -> Void)? | |
var errorHandler: ((Error) -> Void)? | |
func writeToPhotoAlbum(image: UIImage) { | |
UIImageWriteToSavedPhotosAlbum(image, self, #selector(saveError), nil) | |
} | |
@objc func saveError(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) { | |
if let error = error { | |
errorHandler?(error) | |
} | |
else { | |
successHandler?() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment