类似于 SwiftUI ViewBuilder,但用于文本
文本生成器
介绍
Text
SwiftUI 中的组合通常很麻烦,尤其是当逻辑影响其格式和内容时。
TextBuilder 利用 Swift Result Builders 的强大功能来解决这个问题。TextBuilder模仿SwiftUI的ViewBuilder,以便在使用点提供熟悉的体验。
用法
TextBuilder 提供了 3 个现成的构建器,具体取决于您需要的文本分隔符。
无空格文本
间隔文本
多行文本
Pro Tip ✨
TextBuilder accepts types directly as if they were plain , and also provides a computed var to remove unwanted code noise when is explicitly needed.String
Text
String.text
Text
Other Separators
There are two options to customize the separator used to compose your .Text
First, you can use :Text.init(separator:content:)
But if you prefer to keep using a result builder, you can:
Try it out!
TextBuilder supports Arena to effortlessly take it for a spin in a playground before you decide to add it to your codebase.
Simply install Arena and run in your terminal.arena davdroman/TextBuilder@branch:main --platform macos
Alternatively, a standalone demo Xcode Playground is also provided in this package.