Did SwiftUI Just Kill Protocol-Oriented Programming?

SwiftUI’s state management is amazing… but it comes with a steep price.

Michael Long
The Startup

--

Balloon Pop by KellyJane on DeviantArt

During WWDC 2015 Apple dropped a small bombshell on the Swift development community during a session titled “Protocol-Oriented Programming in Swift”. In it Apple demonstrated just how Protocol-Oriented Programming (POP) could free us from the constraints of traditional class-based object hierarchies.

Swift hasn’t been the same since.

Then, just over a year ago during WWDC 2019, Apple dropped another nuke and introduced SwiftUI — its proposed user-interface replacement for the ever venerable UIKit and AppKit.

There’s just one problem.

SwiftUI and Protocol-Oriented Programming don’t get along very well.

To see why, let’s start with an example.

SwiftUI and the ObservableObject

Say that we’ve begun a new SwiftUI project and that we’re writing YAARR: Yet-Another-Another-RSS-Reader.

At its most basic level YAARR will need an observable object that provides a list of articles. And let’s say that object currently looks like the following:

class FeedProvider: ObservableObject {
@Published var…

--

--

Michael Long
The Startup

I write about Apple, Swift, and SwiftUI in particular, and technology in general. I'm also a Lead iOS Engineer at InRhythm, a modern digital consulting firm.