Contents

tunous/joinedtext

**DEPRECATED:** This library was created while result builders (previously known as function builders) were not yet officially a part of Swift language. Now you can use **[TextBuilder](https://github.com/davdroman/TextBuilder)** library by [David Roman](https://github.com/davdrom

Usage

Basics

You can use Text(_ content:) initializer to build your sentence from multiple Text views provided in passed closure.

Text {
    Text("Example")
    Text("sentence").bold()
}

Output:

Example sentence

String separator

By default all Texts declared inside of content block will be separated by a space character. You can change this behavior by providing your own separator text.

Text(separator: "-") {
    Text("joined")
    Text("with")
    Text("dashes")
}

Output:

joined-with-dashes

Advanced separator

For even more control, like additional styling, pass in Text instance as a separator.

Text(separator: Text(" ! ").bold()) {
    Text("bold")
    Text("exclamation")
    Text("mark")
}

Output:

bold ! exclamation ! mark

Control flow

Inside of text definition blocks you can use control flow statements such as if, switch or if let to build your combined Text.

Text {
   Text("Hello,")
   if let name = yourName {
       Text(name).bold()
   } else {
       Text("what is your name?")
   }
}

Output:

Hello, Łukasz

Package Metadata

Repository: tunous/joinedtext

Default branch: main

README: README.md