swift 和 xcode
Last year, after Apple released the first beta of Xcode 11 with native support for Swift Package Manager (SPM) built in, I wrote a post on how we can leverage this to build modular apps with Swift Packages.
去年,在苹果发布了Xcode 11的第一个beta版本并内置对Swift Package Manager(SPM)的本机支持之后, 我写了一篇文章 ,介绍了如何利用它来利用Swift Packages构建模块化应用程序。
In it, I touted that it would make it possible to ditch Cocoapods as a dependency manager, but what we ran into quickly was a limitation with being unable to include resources in a Package, like colour assets, fonts, storyboards/xibs etc.
在其中,我吹捧说它有可能放弃Cocoapods成为依赖管理器,但是我们很快遇到的一个局限是无法在Package中包含资源,例如颜色资产,字体,情节提要/ xibs等。
Thankfully, Xcode 12 includes the latest version of SPM which now allows Packages to include any resources, by including a new static property on Bundle
named .module
. This Bundle
instance references the current module, rather than just being able to reference the current target.
值得庆幸的是,Xcode 12包含了最新版本的SPM,该软件包现在允许Packages通过在Bundle
名为.module
的新静态属性来包含任何资源。 该Bundle
实例引用当前模块 ,而不仅仅是能够引用当前目标 。
In this post, we’ll update our project from last year to include some assets which we can expose from the Package for use in any other module or target!
在这篇文章中,我们将从去年开始更新项目,以包括一些我们可以从Package中公开的资产,以用于任何其他模块或目标!
第1步 (Step 1)
To continue, first follow the steps in last year’s post, then come back here and we’ll carry on from there.
要继续,请先按照去年的帖子中的步骤进行操作 ,然后再回到此处,我们将在此继续进行。
NOTE: You’ll need to use Xcode 12 instead of Xcode 11. Since you’ll be using Xcode 12 and a new version of SPM, you may encounter some slight differences in how to set up a module from last year’s post.
注意:您将需要使用Xcode 12而不是Xcode11。由于您将使用Xcode 12和新版本的SPM,因此与去年的帖子相比,在设置模块方面可能会遇到一些细微的差异。
Notably, you’ll have to provide a package name as well as a product name when declaring dependencies in FantasticFeature. You can just use the same value for both.
值得注意的是, 在FantasticFeature中声明依赖项时 ,必须提供 程序