Creating a swift package with an example app

SPM make it easy to create, distribute, import and use a package. It is easier to create a package with an example app inside for use to pick up and for you to debug with.
Here are how-to steps:

Steps

  1. Assuming you have created a package already. Navigate to the path of your package, and make a group(e.g. DemoApp):
    1. notion image
  1. Then create a new Project named DemoApp or whatever you like inside the new group.(Since it is more likely to manage the package via git outside, you may not want to check “create git repository” when creating the project).
    1. I have already created the project so it’s not empty here.
      I have already created the project so it’s not empty here.
  1. Go to File→Add File Dependencies…, and click “Add Local…” to add your package that contains this project.(If you are using Xcode 15, please jump to section “Xcode 15 adding local packages”)
notion image
  1. Done. Now you can import the package in this demo app. You can also rebuild to see what happened after you change the package’s source code locally.

Xcode 15 adding local packages

Xcode 15 will prevent and alert us if we want to add packages in the group which contains the project through SPM. Fortunately there is a roundabout way to tackle with the problem.
notion image
  1. In target’s “general” tab, add an embedded library(your package).
    1. notion image
  1. In “Build Phases” tab, link your package.
    1. notion image
  1. Done.
 
A project structure is like this repo.
 
你觉得这篇文章怎么样?
YYDS
比心
加油
菜狗
views

Loading Comments...