Swift 包和模块有什么区别?

What is the difference between a Swift package and a module?

Swift有模块化代码,可以整理成模块

但是您可以使用 Swift 包管理器来获取和安装模块。

"Swift package"和"Swift module"有区别吗?我应该什么时候使用一个短语或另一个短语?

Swift.org

所述

Modules: Swift organizes code into modules. Each module specifies a namespace and enforces access controls on which parts of that code can be used outside of the module.

A program may have all of its code in a single module, or it may import other modules as dependencies. Aside from the handful of system-provided modules, such as Darwin on macOS or Glibc on Linux, most dependencies require code to be downloaded and built in order to be used.

When you use a separate module for code that solves a particular problem, that code can be reused in other situations. For example, a module that provides functionality for making network requests can be shared between a photo sharing app and a weather app. Using modules lets you build on top of other developers’ code rather than reimplementing the same functionality yourself.

Packages: A package consists of Swift source files and a manifest file. The manifest file, called Package.swift, defines the package’s name and its contents using the PackageDescription module.

A package has one or more targets. Each target specifies a product and may declare one or more dependencies.

Swift 包是源代码的集合...您可以将其视为一个独立的项目,它有自己的版本和存储库。 Swift 语言本身目前不了解包,它是仅由 Swift 包管理器使用的概念。

一个Swift包可以包含一个或多个Swift模块——每个Swift模块语言所知道的东西,并且例如,Swift 模块定义了诸如访问控制 (publicinternalprivate) 之类的范围。 Swift 包还可以包含其他类型的目标或模块,例如它可以包含 C 源代码主体以构建到库中。

Swift 包在某种意义上类似于 Xcode 项目,Swift 模块类似于 Xcode 目标。

举个具体的例子https://github.com/apple/example-package-fisheryates 是一个 Swift 包 (由顶层的 Package.swift 表示),由其 URL 标识,它包含一个 Swift 模块有两个来源: https://github.com/apple/example-package-fisheryates/tree/master/Sources.