Post

Part 10: Roundup

So I'm done. The point of these articles was for me to figure out how much code could really be shared between Mac, iOS, tvOS and watch (and even in part 8b, visionOS) and the answer is: all of it.

Here's the final project structure as of Part 9.


We have a shared Model folder containing the CoreData/CloudKit model and persistence classes.

We have an Apps/AppShared folder containing the App and its ContentView. The only reason the ListOfThingsView was pulled out was because I made a decision to keep interactivity only available on iOS due to expediency and my own lack of experience. There's no real reason to split these views and so it could have been in AppShared too.

That leaves the Apps/JustOneThing and Apps/JustOneThingWatch folder - one for each target containing just configuration information - The Info.plist and per target entitlements.

On the Widget side, we have our Widgets/WidgetShared folder that contains our System and Accessory widgets, each of which can be used on multiple platforms, along with the widget bundle that collects them. A single TimelineProvider is there too, and all the assets. In the case of the Widgets (unlike the apps) we're able to share the Info.plist. This folder also contains the Intent Definition file.

Each of the target specific folders for Mac, Phone and Watch widgets only contains the platform's entitlements file.


I've been at pains to point out throughout that this is not really a full, complicated project. It's still pretty close the templates Xcode generates, just coalesced into a single project. Xcode templates showed us how to use a CloudKit data store in a SwiftUI app. Xcode templates showed us how to make a Multiplatform app. Xcode templates showed us how to create configurable widgets for all three platforms.

It's been fun to try and pull them all together and figure out where they overlap and where they differ. The end result, I hope, make it clear where we can save time (and maybe bugs) by changing code once, instead of multiple, repeated places.

This post is licensed under CC BY 4.0 by the author.

Trending Tags