A Swift macro that provides ViewBuilder-like syntax for composing Text in SwiftUI with support for control flow and separators.
TextBuilder is a Swift macro that simplifies Text composition in SwiftUI by providing a builder-style syntax similar to ViewBuilder. It addresses the common pain point of cumbersome text formatting and conditional logic in SwiftUI applications, making text composition more intuitive and readable.
SwiftUI developers building iOS, macOS, watchOS, or tvOS applications who need to compose complex, formatted, or conditional text content in their views.
Developers choose TextBuilder because it brings the declarative, compositional power of ViewBuilder to Text, enabling cleaner and more maintainable SwiftUI code with support for separators, direct string integration, and control flow statements.
Like a SwiftUI ViewBuilder, but for Text
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Mimics SwiftUI's ViewBuilder, making text composition declarative and readable by transforming functions into concatenated Text segments, as shown in the basic usage example.
Allows insertion of custom separators like spaces or newlines between text segments, enabling precise layout control for multiline or spaced text, demonstrated in the separator examples.
Accepts String literals and StringProtocol types directly with a .text property for chaining modifiers, reducing boilerplate code, as illustrated in the string support section.
Supports Swift control flow statements including if, if let, and for loops within the builder, enabling dynamic text generation without complex workarounds.
The macro cannot be applied to computed properties due to Swift limitations (referenced in README), forcing developers to use functions instead, which may disrupt code organization preferences.
Relies on Swift macros, which can introduce tooling issues, such as IDE instability or compatibility problems with older Xcode versions, adding overhead for setup and debugging.
Primarily beneficial for complex text composition; for straightforward text, it adds unnecessary abstraction and dependency compared to native SwiftUI Text views.