Modern UIKit: Observation

Episode #283 • Jun 17, 2024 • Subscriber-Only

It’s time to build modern tools for UIKit from scratch, heavily inspired by SwiftUI and using the Observation framework. Surprisingly, Swift 5.9’s observation tools can be used in UIKit, and in fact they work great, despite being specifically tuned for SwiftUI.

Collection

Modern UIKit

Observation
Introduction
00:00
Observation in UIKit
01:51
Adding more behavior
14:05
Animation
25:54
Back-porting to iOS 13
33:29
Next time: state-driven navigation
40:00

Unlock This Episode

Our Free plan includes 1 subscriber-only episode of your choice, plus weekly updates from our newsletter.

Introduction

Brandon: Well, this is pretty incredible.

In just a short amount of time we have been able to build a pretty complex UIKit app from scratch that features many of the things that real world apps need to deal with:

  • Driving navigation from state, and we dealt with 3 forms of navigation: alerts, sheets and drill-downs.
  • Forming 2-way bindings between our models and UI controls.
  • Observing state changes in a model for updating UI elements.
  • And dealing with complex collection views.

And we were able to accomplish all of this using precise, modern techniques, all thanks to the observation tools in Swift and our UIKitNavigation library.

Stephen: And we want to remark again how important it was for us to perform our domain modeling exercise first and in complete isolation. We built 3 observable models for 3 of our features without ever once thinking about view specific needs. And instead, when it came time to build the view, we bent the view to the will of the model to make things work.

Brandon: And that means we can reuse those models in a variety of view paradigms and platforms. We could rebuild those UIKit view controllers using SwiftUI, or we could build views for Windows, Linux, WebAssembly, or who knows what else! The possibilities are endless because we kept our domain models focused on just the business logic, and let the view flow freely from it.

Stephen: So, this has been a lot of fun, but now it’s time to dig a lot deeper. We have showed off a lot of cool tools in the past episode, but what does it take to create these seemingly magical tools? Well, with a bit of hard work we can build them from scratch, and along the way we will get some deep insights into how SwiftUI works under the hood, and even get an understanding of why SwiftUI sometimes doesn’t work the way we expect.

So let’s begin.

This episode is for subscribers only.

Subscribe to Point-Free

Access this episode, plus all past and future episodes when you become a subscriber.

See plans and pricing

Already a subscriber? Log in

References

Collection: Modern SwiftUI

Brandon Williams & Stephen Celis • Monday Nov 28, 2022

What does it take to build a vanilla SwiftUI application with best, modern practices? We rebuild Apple’s Scrumdinger code sample, a decently complex application that tackles real world problems, in a way that can be tested, modularized, and uses all of Swift’s powerful domain modeling tools.

SwiftUI Navigation

Brandon Williams & Stephen Celis • Tuesday Nov 16, 2021

After 9 episodes exploring SwiftUI navigation from the ground up, we open sourced a library with all new tools for making SwiftUI navigation simpler, more ergonomic and more precise.

SwiftUI Navigation

Brandon Williams & Stephen Celis • Tuesday Sep 7, 2021

A library we open sourced. Tools for making SwiftUI navigation simpler, more ergonomic and more precise.

CasePaths

Brandon Williams & Stephen Celis

CasePaths is one of our open source projects for bringing the power and ergonomics of key paths to enums.

Clocks

Brandon Williams & Stephen Celis • Monday Jan 8, 2024

Our back-port of Swift’s observation tools.

Downloads