Skip to content

NickMeepo/PhotoAssetSaveSupported

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

PhotoAssetSaveSupported

A very simple swift protocol using UIImage method UIImageWriteToSavedPhotosAlbum to save UIImage in system`s photo album.

Demo:

class SinglePhotoVC: UIViewController, PhotoAssetSaveSupported {
   //MARK: PhotoAssetSaveSupported defined function.
   func photoAssetSaved(image: UIImage?, didFinishSavingWithError error: NSError?, contextInfo: UnsafeMutableRawPointer?) {
       if error == nil {
         //Save Image Success!
       } else {
         //Save Image Failure!
       }
 }
  
  //Save Image Action
   func saveImage(_ image: UIImage) {
       //UIImage`s extension method -> photoAssetSaved:target:context:
       //target is instance satisied PhotoAssetSaveSupported protocol.
       image.photoAssetSaved(target: self, context: nil)
       
       //Or use PhotoAssetSaveSupported protocol`s extension function -> save:asset:context, same effect as above.
       self.save(asset: image, context: nil)
   }
}

Warning:

You must add "Privacy - Photo Library Additions Usage Description" (NSPhotoLibraryAddUsageDescription) in your info.plist.

About

Swift Protocol to use UIImageWriteToSavedPhotosAlbum

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages