Custom EXIF Data Using Swift

I love chat and messaging apps. Especially those with the simpliest interfaces. I respect the art of simplicity and having built a few myself there are multiple UI / UX considerations and “gotchas” that can seem like a huge effort, but the payoff is worth everyline of code.

One of the puzzels that I was interested in solving was how to differentiate between a video preview attachment and image preview attachment. The first step was pretty straight forward. If you used the camera to take a picture, record a video, or pick from your photo library there is a thumbnail image inserted into the textview. Once the message is saved then the problem solving begins. When a list of messages is returned, how do you distinquish between possible heterongenous image thumbnails and video image thumbnails with possible text?

One option is setup your Message modeling to distinquish between the categories (image and video), but would require extra types on your model. This is not necessary a bad thing, but an extra layer of complexity to consider when extending or modifying your models going forward.

The most straight forward way that I came up with is to modify the EXIF data on the image, specifically the kCGImagePropertyExifUserComment property. I would inspect a Message object for any attachments. If the type was image (other types include GPS, link and custom) then read and parse the kCGImagePropertyExifUserComment property. When the user tapped on the image I knew how to handle the sebsequent view transition: image preview or play the video.

If you have other ways of handling this type of scenario I would love to hear about it.

Gist Playground

Like what you read? Give Cory D. Wiles a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.