We’ve arrived at day 66 of the 100 Days of SwiftUI! We done most of the work for our Instafilter app yesterday. We’ll be putting the finishing touches to it today so that we’ve another project under our belt. To do this, we need to dive into UIKit once again, so let’s take a look!
Customizing our filter using confirmationDialog()
When we finished the first part of the implementation yesterday, the app worked fine. However, users were only able to apply a single effect. This isn’t quite as extensive as we want our app to be, of course, so we’ll need to implement a system that allows our users to choose from multiple filters that are provided by Core Image.
Saving the filtered image using UIImageWriteToSavedPhotosAlbum()
With all of the hard work done by our users to edit their images, it would be a shame if they could not save them to their galleries. As of now, they can’t. However, we’re going to solve this by adding the required functionality to the save button.
As I explained previously, the
Hacking with Swift, Paul Hudson (@twostraws)UIImageWriteToSavedPhotosAlbum()
function does everything we need, but it has the catch that it needs to be used with some code that really doesn’t fit well with SwiftUI: it needs to be a class that inherits fromNSObject
, have a callback method that is marked with@objc
, then point to that method using the#selector
compiler directive.
Wrap up
And that’s it for day 66 and another project has been added to our portfolio. Not too shabby! This was quite a difficult project, mainly because we had to dip into Apple’s UIKit, which really does work differently from SwiftUI. It’s now time to recharge as we face a challenge day tomorrow. Until then!
100 Days of SwiftUI – Day 66