Skip to content
Mihaela's Labv1.124

One Project, Every Apple UI Framework

Mac, iPhone and iPad, in SwiftUI and in AppKit and UIKit. How I build every app for all of them with one Xcode project and one local package, and a template you can download

One Project, Every Apple UI Framework

I always build for every Apple UI framework: SwiftUI, AppKit and UIKit, on Mac, iPhone and iPad. A feature is not finished when it works in one of them: it has to work in every app that uses it. That is what I mean by universal Apple development.

The short version: one Xcode project at the root with no workspace, a thin app for every platform and UI framework, and one local package where each feature is a target. There is a template for it, ready to download.

Download the template here

What working this way demands

A project with both interfaces has six apps, and they can easily become six places to write the same thing. I avoid that with three rules.

  • App targets stay thin. They start the app and load AppFeature.

  • Features live in one local package, each as its own target, with its own sources and tests.

  • Each app links only what it uses, and a feature has to work wherever it is linked.

This is how thin they are, from a project the template generates. The Mac app in SwiftUI:

import AppFeature
import SidebarFeature
import SwiftUI

@main
struct MainApp: App {
    var body: some Scene {
        WindowGroup {
            AppFeature.Screen.RootView {
                SidebarFeature.Screen.Panel()
            }
        }
    }
}

The iPad app differs only in what it links:

import AppFeature
import CaptureFeature
import SidebarFeature
import SwiftUI

@main
struct MainApp: App {
    var body: some Scene {
        WindowGroup {
            AppFeature.Screen.RootView {
                SidebarFeature.Screen.Panel()
                CaptureFeature.Screen.Panel()
            }
        }
    }
}

The scene delegate of the iPhone app in UIKit (its app delegate only names this class):

import AppFeature
import CaptureFeature
import UIKit

final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    var window: UIWindow?

    func scene(_ scene: UIScene, willConnectTo _: UISceneSession, options _: UIScene.ConnectionOptions) {
        guard let windowScene = scene as? UIWindowScene else { return }
        let window = UIWindow(windowScene: windowScene)
        window.rootViewController = AppFeature.Screen.ViewController(sections: [CaptureFeature.Screen.ViewController()])
        window.makeKeyAndVisible()
        self.window = window
    }
}

And the Mac app in AppKit:

import AppFeature
import AppKit
import SidebarFeature

@main
final class AppDelegate: NSObject, NSApplicationDelegate {
    private var window: NSWindow?

    static func main() {
        let application = NSApplication.shared
        let delegate = AppDelegate()
        application.delegate = delegate
        application.setActivationPolicy(.regular)
        application.run()
    }

    func applicationDidFinishLaunching(_: Notification) {
        NSApp.mainMenu = AppFeature.Menu.Bar.make()
        let root = AppFeature.Screen.ViewController(sections: [SidebarFeature.Screen.ViewController()])
        let window = NSWindow(contentViewController: root)
        window.makeKeyAndOrderFront(nil)
        self.window = window
        NSApp.activate()
    }

    func applicationShouldTerminateAfterLastWindowClosed(_: NSApplication) -> Bool {
        true
    }
}

One model, native in each framework

Every framework does not mean one layout everywhere. I optimize the interface for the person using it, through the native presentation of each platform, not for the convenience of one shared layout. Sameness across platforms is not a goal in itself, so two versions may differ where the platforms do.

In my deepest example of this, an animation library, each feature is split into targets inside the one package:

  • A model of plain values that imports no UI framework.

  • A Core Animation layer target, shared by the UIKit and AppKit versions.

  • A target for each framework: UIKit for iPhone and iPad, AppKit for the Mac, and SwiftUI, which takes only the model and hosts no platform view.

No version depends on another. Each one gets its own small demo app, all in one project.

Building for all of them is not the same as having seen all of them work. swift test covers the Mac, the iOS-only code is mostly compiled for the Simulator without being run, and I have UI scenarios for very little of it so far.

The layout in a project

This is a project with both interfaces and the demo features switched on. With one interface there are three apps, and without the demo features there is no SidebarFeature or CaptureFeature.

Shop/
  Shop.xcodeproj        the one project, the file you open
  Apps/
    MacSwiftUI/         thin app targets
    PhoneSwiftUI/
    PadSwiftUI/
    MacAppKit/
    PhoneUIKit/
    PadUIKit/
    ...UITests/         one UI test folder per app
  Packages/
    Package.swift       the one manifest
    Sources/
      AppFeature/
      AppSettings/
      SidebarFeature/
      CaptureFeature/
    Tests/

On disk the folder is Packages/. Xcode shows it under the package’s name, AppPackage.

Package tests run from the one package, and apps build from the project:

swift test --package-path Packages
xcodebuild -project Shop.xcodeproj -scheme MacSwiftUI \
  -configuration Debug -destination 'platform=macOS' build

swift test runs on the Mac, so code that exists only for UIKit or iOS is not tested by it.

The template

You can use this layout without setting it up by hand. The template is called App with a Local Package, it is MIT licensed, and it makes thin apps for Mac, iPhone and iPad with one local package. Apple Watch, Apple TV and Apple Vision Pro are not in it.

Get it here: codeberg.org/Mihaela/PackagesAppTemplate

Install it:

git clone https://codeberg.org/Mihaela/PackagesAppTemplate.git
cd PackagesAppTemplate
swift Install.swift

Then choose File, New, Project in Xcode and select macOS, where the template is listed even though it also makes the iPhone and iPad apps. Under My Templates, choose App with a Local Package. If it does not show, quit Xcode and open it again.

Xcode’s New Project window with macOS selected: under the heading My Templates, the project template App with a Local Package is selected.

To update after downloading a newer version, run swift Install.swift --replace. To remove it, run swift Install.swift --uninstall.

Every generated project is a small table and detail app, and depends on a package from GitHub, Apple’s swift-algorithms, to show that a remote package sits happily beside the local one.

With the demo features on, the screens differ on purpose, because each app links only what it uses: the Mac apps take SidebarFeature, the iPhone apps take CaptureFeature, and the iPad apps take both.

On the Mac, here in AppKit, the list sits in a sidebar with the detail beside it. The last line of the detail comes from SidebarFeature.

The demo app on the Mac in AppKit: a sidebar listing Apps, Package and GitHub, and a detail view saying that the Mac app is a thin target that loads AppFeature.

On the iPhone, here in SwiftUI, the same app opens on the list, because there is no room for both. Tapping a row opens its detail.

The demo app on an iPhone simulator in SwiftUI: a list with the sections Apps, Package and GitHub.

On the iPad, again in SwiftUI, list and detail are side by side. This app links both demo features, so both of their lines appear. I tapped the iPad row to show them.

The demo app on an iPad simulator in SwiftUI: the list with the iPad row selected, beside a detail view with lines from the AppSettings, SidebarFeature and CaptureFeature targets.

Beside Xcode’s usual fields, the template asks three questions:

Xcode’s New Project options page for the template: Product Name, Team and Organization Identifier, then an Interface menu set to SwiftUI and two unchecked boxes, Include demo features and Add GitHub Actions workflow.

The menu holds three choices, and each box is simply on or off:

QuestionChoices
InterfaceSwiftUI, UIKit and AppKit, Both
Include demo featuresoff, on
Add GitHub Actions workflowoff, on

That makes 3 x 2 x 2 = 12 different projects. Product Name, Team and Organization Identifier are not counted: they change names and signing, not what is generated. Here they are, with example names:

#ProjectInterfaceInclude demo featuresAdd GitHub Actions workflowApps
1ShopSwiftUISwiftUIoffoff3
2ShopSwiftUIFeaturesSwiftUIonoff3
3ShopSwiftUICISwiftUIoffon3
4ShopSwiftUIFeaturesCISwiftUIonon3
5ShopNativeUIKit and AppKitoffoff3
6ShopNativeFeaturesUIKit and AppKitonoff3
7ShopNativeCIUIKit and AppKitoffon3
8ShopNativeFeaturesCIUIKit and AppKitonon3
9ShopBothBothoffoff6
10ShopBothFeaturesBothonoff6
11ShopBothCIBothoffon6
12ShopBothFeaturesCIBothonon6

Here is the largest of them, ShopBothFeatures, open in Xcode: six apps and their UI test folders at the top, then the one package with its targets, and below it the dependencies from GitHub. The file on the right is the SwiftUI root view that the SwiftUI apps share.

Xcode with a generated project: the navigator shows the Apps folder with six app targets and their UI test folders, then one local package whose Sources hold AppFeature, AppSettings, CaptureFeature and SidebarFeature, and below it the package dependencies swift-algorithms and swift-numerics. The editor shows the SwiftUI root view of AppFeature, a split view with a list and a detail.

All twelve are in the repository’s Projects/ folder, so you can look before installing anything. With Xcode 27.2, all of them build, 48 apps in total, and their package tests pass. What I have not tried: creating a project from the New dialog, running the GitHub workflow, running the UI tests, and older Xcode versions.

Why I said goodbye to the workspace

My layout used to start with a workspace: one window over the app projects, the Swift packages and the documents. Then I started working on an app about Xcode templates, and I met the obstacle. When you choose File, New, Project, the dialog ends in a project. It does not leave you in an open workspace. What remains is a manual step or a workaround, and the ones I could think of were ugly and cumbersome.

So I asked what the workspace was giving me. It showed everything in one window, it listed the documents, and in some projects it was the only link between an app and its package: the app linked the package’s products without holding a reference to the package. Take the workspace away from a project like that and Xcode reports Missing package product. A single project can hold the reference itself, which Apple documents as organizing your code with local packages.

I did not want to decide this from memory. In a small trial with Xcode 27.2, a plain project template produced a project, two app targets, a UI test bundle and a local package beside the project, with no workspace.

One warning: a project I put together without a template passed its command line build and then failed on Run, with Unable to resolve module dependency, because ONLY_ACTIVE_ARCH was missing in Debug. Check with the Run button, not only the command line.

What it costs

  • One project file for everything. Every new app edits the same file.

  • No project per app, if you liked each app having its own.

  • One dependency list. Linking only what an app uses does not shorten it: every app still resolves all of the package’s dependencies, and so does anyone else who uses the package.

  • Unique target names. A target cannot share its name with a target in any package you depend on, or resolution fails.

  • Access levels. When you split features into targets, what was internal and is now used across them must become package, and memberwise initializers have to be written out.

I have not compared indexing speed, or how the project file behaves when two people merge changes to it.

The app that led me here

I have been interested in templates for a long time. Working this way is one of the reasons I am now building an app for them: when every project needs the same set of targets, I want the template to do that work.

I originally meant to write about how to create Xcode templates. Then I decided that it is far too complicated to explain, so I am building an app instead.

Even this small template surprised me: documentation is scarce, and when something is wrong, Xcode often says nothing until you build.

The app creates templates visually. It is still in development, so there is nothing to download yet.

It has an editor for the template source, with a template library, an outline, diagnostics and a diagram of the whole template. Here it has Apple’s Cocoa Touch Class template open.

Editor in a development build with Apple’s Cocoa Touch Class template open: the template library at the left, the template source in the middle with the template’s icons above it, and at the right a diagram branching from the template to its options and files.

The app did not make the template in this post; that one comes from a small Swift generator. If you want to hear when there is something to try, Apple UI Insider, my free newsletter, is where I will say so.

The picture at the top of this post was drawn by a Swift program of about 245 lines with my own drawing library, PureDraw. It draws only shapes: a gradient background, rounded rectangles, ellipses, polygons, curves and shadows. PureDraw rasterizes them and writes the PNG. No image generator or outside drawing tool was used, and no pixel was edited by hand.

Apple UI Insider

A free newsletter on how Apple frameworks really work, from Core Graphics and Core Animation to SwiftUI and motion systems.

Powered by Buttondown.