Should I divide my code's components into targets or packages?

Thought it might be useful to future readers to post an update on what I ended up doing

Here's my structure (in terms of packages/products/targets, not the file hierarchy):

Foo Xcode Workspace
├── 🛠 Foo app Xcode project
├── 📦 FooShell Swift Package
│   └── 🏛 FooShell library product
│       └── 🎯 FooShell target
└── 📦 FooComponents Swift Package
    ├── 🏛 FooCore library product
    │   └── 🎯 FooCore target
    ├── 🏛 FooUtils library product
    │   └── 🎯 FooUtils target
    └── ... and so on

I wanted to make FooShell (which contains all my storyboards, view controllers, etc.) into just another library product under the FooComponents package. But, it appears that you can't specify platform requirements on a per-product or per-target basis, so I ended up needing to split it off into its own Swift package.

In FooShell, I imported FooComponents as a local dependency:

//...
dependencies: [
	.package(path: "../GizmoComponents"),
],
targets: [
	 .target(
		name: "GizmoShell",
		dependencies: [
			.product(name: "GizmoCore", package: "GizmoComponents"),
   	 ]
	),
   //...
],
//...
1 Like