

We already have this loadImage() method from our previous work: func loadImage() With that done, we can now use the UIImageWriteToSavedPhotosAlbum() method to write out a picture. For the value on its right, please enter the text “We want to save the filtered photo.” You’ll see a dropdown list of options to choose from – I’d like you to scroll down and select “Privacy - Photo Library Additions Usage Description”. To add your permission string, right-click on any of the existing options then choose Add Row. iOS will take care of asking for permission and checking the response, but we need to provide a short string explaining to users why we want to write images in the first place. You see, writing to the photo library is a protected operation, which means we can’t do it without explicit permission from the user.

This is where you can add a whole range of configuration options for your project, but right now there’s one specific option we need. Now you’ll see a bunch of tabs across the top, including General, Signing & Capabilities, and more – select Info from there.You’ll see Instafilter listed under both PROJECT and TARGETS.It will have your project name, Instafilter. In the Project Navigator, select the top item in the tree.These options all live in a particular place in Xcode, and it’s bizarrely hard to find unless you know what you’re doing: This isn’t code: these options must all be declared ahead of time, in a separate file, so the system can read them without having to run our app.

Every project we build has a whole bunch of these baked right in, describing which interface orientations we support, the version number of our app, and other fixed pieces of data. At the very least it will make you really appreciate how much better SwiftUI is!īefore we write any code, we need to do something new: we need to add a configuration option for our project. This uses a UIKit function called UIImageWriteToSavedPhotosAlbum(), which in its simplest form is trivial to use, but in order to make it work usefully you need to wade back into UIKit. Before we’re done with the techniques for this project, there’s one last piece of UIKit joy we need to tackle: once we’ve processed the user’s image we’ll get a UIImage back, but we need a way to save that processed image to the user’s photo library.
