Modular app sample project #3173
wltrup
started this conversation in
Show and tell
Replies: 2 comments 2 replies
-
Beta Was this translation helpful? Give feedback.
0 replies
-
Hey, sorry for being somewhat off-topic here (not enough experience with modularization to fully appreciate this post), but have you found a way to get rid of the warnings about KeyPath sendability? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone and @jberstler 👋
I've been experimenting with setting up modular apps and, in view of a question posted recently here on that very subject, I thought I'd share the results of my efforts.
The setup I ended up with works great, except for the occasional hiccup caused by Xcode getting confused by Swift packages. I find that resetting the package cache resolves the issues I've encountered. Other than that, it's smooth sailing most of the time.
The setup lets me have multiple executable targets (even of multiple platforms) all sharing the same package of modules, which the executables can "enter into" by judiciously choosing specific modules to add to the "Frameworks, Libraries, and Embedded Content" section of the executable's target. More on that in a bit.
I'm attaching a simple sample project that highlights the main ideas. I encourage everyone reading this to open it before continuing to read this post.
To create a modular project, start by following these steps:
At this point, you should have something like the following (ignoring the contents of "Executables" for now):
This step is how you'd add more executable projects to the workspace. If you want, you can organize them by some criteria. For example, I have an extra directory there for "Preview Apps", which are small apps that present a specific portion of the main app's UI. I occasionally also have a directory for "Utility Apps", small apps that I might need to write to experiment with some idea before committing myself to it in the main app(s).
Now, so far, the executable is not connected in any way to the "Modules" package so the next step is to set that up.
And that's it. The new executable project is now ready. I generally do some house-cleaning on its source (see the sample project) and also set project settings as needed. For example, the sample project has the Swift 6 language mode and strict concurrency both enabled. By the way, I just realized that that means you'll need to have the Xcode 16 beta installed. If not, you should open the sample project in Xcode 15 and change the language mode back to Swift 5.10.
A couple of extra things I added to the sample project:
AppFeature
declares@SharedReader
properties for them so that its view can display those dates. Here's the result of running the sample project (in Xcode 16 beta):And that's it. You can build and test individual modules in isolation and integrate them using the package manifest and the import mechanism. Once you've set up the executable target as I recommended above, you hardly ever have to touch it again.
I've been using this setup for quite a while now and it works very well (again, sans the occasional Xcode hiccup). However, I do have a few questions that @mbrandonw, @stephencelis , or someone else might be able to answer:
KeyPath
sendabilityI hope this post is useful to anyone and everyone struggling to get a modular app going.
Cheers!
ModularAppSample.zip
Beta Was this translation helpful? Give feedback.
All reactions