Member-only story
Re: UIKit/AppKit-Free SwiftUI App
In this short read, I revisit my SwiftUI app in an attempt to remove the last remnants of UIKit and AppKit.
In last year’s revision of my iOS/macOS app Worm, where I explored the state of Apple’s SDKs, I complained that I couldn’t quite get rid of UIKit/AppKit. The blocker was Image — specifically, creating one from data downloaded over the internet.
Back then, my solution was to create a UIImage/NSImage from Data and initialise Image from it. I claimed there was no other way.
I was wrong.
Not a member? Read here for free.
But before we get to the better approach, let’s look at what I had been doing before.
The Wrong Way
At the time, I was rather proud of the workaround I built to smooth over the differences between iOS and macOS SDKs.
First, I defined a universal type alias:
#if os(iOS)
import UIKit
typealias UniversalImage = UIImage
#elseif os(macOS)
import AppKit
typealias UniversalImage = NSImage
#endifThen, I wrapped it in a SwiftUI view that worked on both platforms:
import SwiftUI
struct UniversalImageView: View {
var body: some View {
#if…