Swift 消费者 -> Swift 静态库
Xcode 版本 10.2.1
创建 Swift 静态库
创建库项目或创建库目标
File -> New -> Project... -> Cocoa Touch Static Library
//or
Project editor -> Add a Target -> Cocoa Touch Static Library
添加文件.swift
Select `.swift` file -> Select File Inspectors Tab -> Target Membership -> Select the target
//or
Project editor -> select a target -> Build Phases -> Compile Sources -> add files
构建库 - ⌘ Command+B或Product -> Build
注意 1:确保为与客户端代码相同的流程架构构建库。注意 2:使用或访问修饰符
公开您的 API 应该对消费者可见[关于]public
open
查找生成的输出[构建位置]
Products group -> lib<product_name>.a -> Show in Finder
目录包括
lib<product_name>.a
- 一个内置的静态库
<product_name>.swiftmodule
. swiftmodule
描述库的接口和编译器版本。该文件夹包括:
.swiftdoc
- 文档
.swiftmodule
- 公共接口/定义
使用 Swift 静态库的 Swift 消费者
Drag and drop
将二进制文件放入 Xcode 项目[关于]
Link Binary
[未定义符号] [链接与嵌入]
Project editor -> select a target -> General -> Linked Frameworks and Libraries -> add -> Add Others... -> point to `lib<target_name>.a` file
//or
Project editor -> select a target -> Build Phases -> Link Binary With Libraries -> add -> Add Others... -> point to `lib<target_name>.a` file
添加Library Search paths(LIBRARY_SEARCH_PATHS)
[找不到库] [递归路径]
Project editor -> select a target -> Build Settings -> Search Paths -> Library Search paths -> add path to the parent of `lib<target_name>.a` file
添加Import Paths
【无此模块】 【递归路径】
Project editor -> select a target -> Build Settings -> Swift Compiler - Search Paths -> Import Paths -> add path to a folder with `.swiftmodule`
将模块导入 Swift 客户端代码[module_name]
import module_name
[更多示例]