> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/ios/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/ios/swift-playgrounds/modules.md).

# 使用模組

Using Modules in Swift Playgrounds Book

{% hint style="warning" %}
從 **Swift Playgrounds 3** 與 **Playground Book 格式版本 6** 開始才支援**模組** (module)。
{% endhint %}

一個 Playgrounds Book 有兩種模組：

* 私有模組：放在 `.playgroundbook/Contents/Modules` 目錄裡面，使用者無法編輯。
* 公有模組：放在 `.playgroundbook/Contents/UserModules` 目錄裡面，使用者可以編輯。

每個模組本身也是一個目錄，必須以 `.playgroundmodule` 為副檔名。裡面所包含的程式原始碼，必須放在 `Sources` 子目錄裡面，例如：如果有一個模組稱為 `Statistics`，裡面有 `MyAPI.swift` 這個檔案，這時的檔案結構為：

* `UserModules/Statistics.playgroundmodule/Sources/MyAPI.swift`

## 📘 參考資料

1. [Using Modules to Share Code in a Playground Book](https://developer.apple.com/documentation/swift_playgrounds/structuring_content_for_swift_playgrounds/using_modules_to_share_code_in_a_playground_book)
2. [Structuring Content for Swift Playgrounds](https://developer.apple.com/documentation/swift_playgrounds/structuring_content_for_swift_playgrounds)
