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
构建库 - ⌘ 命令 + B 或Product -> Build
注意 1:确保为与客户端代码相同的流程架构构建库。
注意 2:使用 public 或 open 访问修饰符[About] 公开您应该对消费者可见的 API
查找生成的输出[Build location]
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项目[About]
Link Binary[Undefined symbols][Link vs Embed]
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)[Library not found for][Recursive path]
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[No such module][Recursive path]
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
[More examples]