2

我正在 Xcode 中开发几个不同的应用程序,并且我使用 Swift 包作为我的“通用”库。在每个项目中,我通过转到项目的“Swift Packages”(“Info”和“Build Settings”旁边)并输入本地“file:///...”url 来添加通用 Swift 包。这检查了一个只读版本。一切都运行良好,但如果我对常用文件进行大量编辑,就会很烦人。我必须:

  • 切换到另一个 Xcode 窗口,其中 Swift 包以读写模式打开。
  • 编辑文件,将它们提交到 git,标记提交
  • 回到应用程序项目,菜单栏 > 文件 > Swift 包 > 重置包缓存(假设我移动了标签,而不是创建一个新标签)

有没有办法简化这个,所以我可以编辑和编译 Swift 包中的文件,而不必每次都执行 git 步骤?

4

1 回答 1

9

I've discovered that I can do this, so I'm answering my own question.

You can use a "local package" as described in this short article from Apple: Developing a Swift Package in Tandem with an App

I keep the same configuration as before — my app project still has a Swift package dependency defined, and that dependency still points to the same URL for the git repo. But now I also checkout/clone a local copy of that repo, into my app's project directory, or maybe one level up if I'm using an Xcode workspace. Then I drag that cloned directory to the Xcode project navigator. As soon as you drop that folder there, Xcode makes some adjustments to its UI, to reflect that it's using it as a local version of the package. You can edit the files there, and push changes back to the main repo. If you delete that local clone, Xcode goes back to using the read-only version like before.

于 2020-04-22T13:55:38.030 回答