Using Modules in Swift Playgrounds Book
從 Swift Playgrounds 3 與 Playground Book 格式版本 6 開始才支援模組 (module)。
一個 Playgrounds Book 有兩種模組:
私有模組:放在 .playgroundbook/Contents/Modules 目錄裡面,使用者無法編輯。
.playgroundbook/Contents/Modules
公有模組:放在 .playgroundbook/Contents/UserModules 目錄裡面,使用者可以編輯。
.playgroundbook/Contents/UserModules
每個模組本身也是一個目錄,必須以 .playgroundmodule 為副檔名。裡面所包含的程式原始碼,必須放在 Sources 子目錄裡面,例如:如果有一個模組稱為 Statistics,裡面有 MyAPI.swift 這個檔案,這時的檔案結構為:
.playgroundmodule
Sources
Statistics
MyAPI.swift
UserModules/Statistics.playgroundmodule/Sources/MyAPI.swift
Using Modules to Share Code in a Playground Bookarrow-up-right
Structuring Content for Swift Playgroundsarrow-up-right
Last updated 5 years ago