Image for post
Image for post
An ode to headphone jacks refusing to go out to pasture on MacBook Pros 🎧.

iOS 12: Notable UIKit Additions

Let’s UIView What’s New #PunGameStrong

Jordan Morgan
Jun 8, 2018 · 6 min read

A quick note — all of my future posts will be published on my dedicated website and this publication is no longer being updated. Thanks for reading!


UITextInputTraits

Apple continues its push towards keeping its user‘s data private and secure, so it’s no surprise to see Cupertino & Friends© extend the password autofill APIs.

let createNewPasswordTextField = UITextField()let newPasswordReqs = UITextInputPasswordRules(descriptor: "required: lower; required: digit; max-consecutive: 3; minlength: 12;”)createNewPasswordTextField.passwordRules = newPasswordReqs// Now, when iOS suggests a new password - these rules will be used to generate it
"key: value;"
  • allowed : Allow a subset of allowed characters
  • max-consecutive : Restrict the number of successive characters
  • lower : a-z
  • special: -~!@#$%^&*_+=`|(){}[:;”’<>,.? ] and space
  • ascii-printable : All ACII printable
  • unicode : All unicode
UITextInputPasswordRules(descriptor: "required: [j,o,r,d,a,n]; max-consecutive: 2; minlength: 12;”)

One Time TFA Codes

In one of my favorite “It just works” APIs that Apple supplies to developers, it’s hard to argue that there’s something more trivial to implement in iOS development that simultaneously brings real value to users than setting a text content type.

aTFAtextField.textContentType = .oneTimeCode

Graphics Rendering

As we’ll briefly discuss later on, iOS 12 has automatic backing store support for views. The depth of their content drives this. So, for example, if you are rendering a grey scale image on the screen iOS will employ an 8 bit per pixel backing store instead of the usual 64 bit per pixel backing store a portrait image would incur.

let rendererFormat = UIGraphicsImageRendererFormat.default()
rendererFormat.preferredRange = .extended // For an extended range image
let renderer = UIGraphicsImageRenderer(size: CGSize(width: 100, height: 100), format: rendererFormat)

The Small Quick Win

Detecting user interface orientations is traditionally frowned upon via Apple’s official stance. And though trait collections offer us most of what we need, it’s still refreshing to see Apple come full circle on all the edge cases with two new additions here:

let device = UIDevice.current
let isFlat = device.orientation.isFlat
let isValid = device.orientation.isValidInterfaceOrientation

Darkness for Days

Also, we have dark mode on iOS, finally! Mojave doesn’t get all the fun!

let darkTraitCollection = UITraitCollection(userInterfaceStyle: .dark)
@available(iOS 12.0, *) public enum UIUserInterfaceStyle : Int {
case unspecified
case light
case dark
}

Notifications

Technically not part of UIKit, but I did have to highlight one welcome change aside from the new grouping capabilities. Look, dealing with notifications is often a pain from a developer perspective. While not a forgone conclusion, the more notification offerings we have to support, generally the issues that could arise grow exponentially.

… And The Free Ones 🙌

iOS 12 is fast. A lot of the improvements we’ll enjoy come from deep within the framework itself. Here, I’ve chosen to highlight API changes you’ll need to put some time into to reap benefits.

Wrapping Up

Personally, I came away more impressed than I thought I would be with iOS 12. Initially, it appeared that a lot of the chatter preemptively declared that iOS 12 would be a day late and dollar short. Last year, we were treated to some marquee features within UIKit like drag and drop — so what could they throw down for us this year?


The Traveled iOS Developer’s Guide

Cocoa Touch, unwrapped and analyzed by @JordanMorgan10.

Jordan Morgan

Written by

iOS @buffer. Author for Pluralsight, contributor to a few books, conference talks and some other stuff! Writing at swiftjectivec.com

The Traveled iOS Developer’s Guide

Cocoa Touch, unwrapped and analyzed by @JordanMorgan10. Updated biweekly.

Jordan Morgan

Written by

iOS @buffer. Author for Pluralsight, contributor to a few books, conference talks and some other stuff! Writing at swiftjectivec.com

The Traveled iOS Developer’s Guide

Cocoa Touch, unwrapped and analyzed by @JordanMorgan10. Updated biweekly.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store