Extending Codable: loading images and colors from JSON

Recently, I began work on a new iOS app and had to work with Codable, the new protocol introduced in Swift 4 that makes converting between Swift types and JSON data incredibly easy. However, Codable has some limitations and issues I had to work around.

While by default Codable supports most common Swift types, including strings, arrays, number types and more, out of the box, it does not support some platform specific types. For example, if you try to use a UIColor or UIImage, you’ll get an error telling you that your Type does not conform to protocol 'Decodable'.

My hopes and predictions for WWDC19

WWDC 2019 promotional image with avatar with subtitle: San Jose, CA from June 3 to 7

Apple recently announced WWDC19, their annual Worldwide Developers Conference, which is taking place in San Jose, California, from June 3 to 7. Every year, over 5000 developers attend WWDC, and it has become one of the major events to attend for macOS or iOS developers.

This is a short* blog post where I outline some of my hopes and predictions for what I want to see at WWDC19, especially around developer APIs and tools but also in terms of consumer features, such as dark mode.

Building my WWDC Scholarship Submission

On March 13 2018, Apple announced WWDC 2018. As in previous years, tickets were available via the ticket lottery, as well as Apple’s scholarship program, where 350 students apply to receive a free ticket and lodging for WWDC.

Although I had just started learning Swift, I decided to try my luck and apply for a scholarship anyways. I was incredibly ecstatic to be awarded a scholarship, and in June 2018 I attended WWDC and learned a ton as well as met tons of other scholars and Apple engineers.

Marzipan Tips: run your iOS app on the Mac

Image of Apple Engineer Craig presenting UIKit on the Mac at WWDC 2018.

In 2017, Apple started an ambitious new project: allowing iOS apps to be ported to macOS. This project, known as Marzipan, was previewed at WWDC 2018, where Apple used it to add previously unavailable Apple apps to macOS Mojave.

While Marzipan is in use on macOS Mojave, Apple has opted not to make it available for developers because of it’s relative instability. However, developers have already managed to create tools to bring iOS apps to macOS using Marzipan thanks to the Apple apps that were ported.

Adding document scanning to your app with WeScan

Animated video showing someone using WeScan to scan a book cover.

Do you need to allow your users to scan documents or other papers? WeScan by WeTransfer is a great, fast iOS framework that allows you to easily add a document scanner to your app, with automatic document detection, PDF support, and a whole lot more.

WeScan is free and available under the MIT License, so it’s the perfect choice if you don’t want to waste time figuring out rectangle detection and perspective correction.

Loading images from asset catalogs

Asset Catalogs are perfect for storing collections of images which you can then display in your app. However, it’s easy to accidentally cause crashes or have to deal with optionals. In this tutorial, we’ll look at 3 different ways to use asset catalog images in our code.

The 3 methods to load images from asset catalogs are image literals, the frequently-used UIImage(named:) initializer, and finally, a custom UIImage initializer.

Implementing dark mode with observers

While dark mode is now available for both tvOS and macOS, it is still not available on iOS. In this tutorial, we’ll see how to set up a custom in-app theming system which lets the user pick between light and dark mode within the app, providing an alternative to a system dark mode.

We’ll also use observers to allow view controllers and other classes to register for appearance updates, so they can update their appearance whenever the theme is changed by the user.

Adding pinch to zoom support to image views

A UIImageView is frequently used for displaying all types of images in iOS apps, but unfortunately, image views don’t support any type of zooming, such as pinch to zoom. In this tutorial, we’ll see how it’s possible to use a UIScrollView to make any image view support pinch to zoom.

As we are using a UIScrollView, the image can also be moved around after zooming, so it feels natural. After adding support for pinch to zoom, we will also add support for double tap to zoom.