Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create swift package and a companion app side-by-side

I'm trying to accomplish the same package organization as this one https://github.com/pointfreeco/swift-composable-architecture. The features I would like to achieve are the following:

  1. Companion app and package live in the same workspace and can be edited side-by-side

enter image description here

  1. Companion app is hosted in the same repo, but it is not downloaded as part of the package checkout

enter image description here

I've tried:

  1. Starting with an empty workspace, then adding a package to it, but then Package.swift won't be at the root of the repo, so this won't work.
  2. Starting with the package File > New > Package. Then created the empty workspace in the same folder. Opened it and drag the package folder onto it. Then added a new app project linking it with the package I will be building. It all seems to work fine. However, now I'm leaving with the Example folder inside my package and I cannot just simply delete the reference to it. Only lets me delete the entire folder.

enter image description here

like image 756
user16401900 Avatar asked Jan 26 '26 19:01

user16401900


1 Answers

Here's what I recommend, as demonstrated in https://github.com/MacPaw/OpenAI 's structure (also derived from swift-composable-architecture's.

Root
|-- Package.swift << Your package
|-- Sources/ << containing your package sources
|-- Demo << Companion app
  |-- Demo.xcodeProj
  |-- App/... << the wiring code of your demo project
  |-- DemoPackage
    |- Package.swift << Your demo app's package, it should declare dependency on the package of your Root ../..
    |- OtherFiles.swift

To summarize,

  1. Create the demo app folder on the same level as your package sources.
  2. Inside Demo app, create a new package DemoPackage, which depends on your Root package ../... This package can contain the bulk of your business logic of your companion app.
  3. Add the DemoPackage locally to your demo app project. Add light wiring wrapper to reference your DemoPackage.

This way, you can write demo app inside a package you offer.

like image 50
Ben Lu Avatar answered Jan 29 '26 11:01

Ben Lu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!