mcritz / TextBundle 文本包

Swift 优先,Swift 最佳的 TextBundle 软件包。支持版本 2 的规范

如果您正在寻找替代实现,请尝试 shinyfrog/TextBundle


安装

Package.swift

dependencies: [
    .package(url: "https://github.com/mcritz/TextBundle.git", .upToNextMajor(from: "1.0.0")),
],

... 以及更 नीचे 在 targets 中…

dependencies: [
    .product(name: "TextBundle", package: "TextBundle"),
],

用法

从磁盘读取

从磁盘读取 TextBundle 文本包,可以是 .textbundle.textpack 格式

let myFileURL: URL = ...
let myTextBundle = try TextBundle.read(myFileURL)
let contents: String = myTextBundle.textContents

创建 bundle

let myBundle = TextBundle(name: "HelloWorld", contents: "# Hello, World!")

写入磁盘

myBundle.bundle(destinationURL: myURL) { bundleFileURL in
    print(bundleFileURL.path)
}

感谢 Guillermo Casales @gcasales 在 Unsplash 上免费提供这张照片 🎁 https://unsplash.com/photos/LQfcolSv2M0