Geoff Pado

Black Highlighter — May 13th, 2019

A fully working app at last! The app can now handle saving an edited photo to the photo library. This completes the full app workflow from asking for photo permissions, to selecting an image to edit, to actually editing the image, and finally saving the finished image.

Getting this final bit of basic functionality involved a little bit of cheating, however. Rather than rewrite our drawing code to draw just a single image, we create copies of our app’s views, and use UIView snapshotting to capture an image of those views. This is done by creating a graphics context the size of our image, and using the method drawHierarchy(in:afterScreenUpdates:) to draw both our image view and redaction view (in that order!) into the graphics context. Then we grab an image from the graphics context, and that’s the final product—drawn exactly like the view before.

Once we have the final, redacted image, we need a way to get it out of the app. Fortunately, there’s an easy solution for this: UIActivityViewController. This class is the “share sheet” that’s used throughout iOS. We simply create a new activity view controller, pass it our image, and it gives us a bunch of different options for what to do with it—including saving it to the photo library. It doesn’t handle saving in place, and we may want a way to save with fewer steps involved than the share sheet, but this accomplishes our main goal for now.

To protect anyone using the app from accidentally throwing away all their work, tapping the “Done” button when there are unsaved changes now pops up an alert asking if you really want to exit. I’m not super happy with the wording on that alert, but that’s an issue for a bug bash stream.

Commits Made

Tickets Closed

Tickets Created

None.

Project Stats

Sessions Completed
17
Days Since Start
43
Issues Closed
23
Issues Open
13
Percent Complete
63.9%

Replay

Watch this session on YouTube: