AttributedStringBuilder

0.1.2

Makes composing NSAttributedString pleasant by expressing each component within a closure
kkiermasz/AttributedStringBuilder

What's New

v0.1.2

2022-05-16T08:46:10Z

Changes

AttributedStringBuilder

AttributedStringBuilder is a simple builder that makes composing NSAttributedString pleasant by expressing each component within a closure.

Tests

Features

It provides two ways of composing attributed strings. The first one is achieved by using new Swift 5.3 function builder feature.

Composing in closure

NSAttributedString {
    "Doesn't that".with(attributes: .font(.boldSystemFont(ofSize: 34)))
    Space()
    Text("look", with: .textColor(.blue))
    "wonderful?"
    NewLine()
}

Composing using chaining

NSAttributedString.Builder()
    .add("Doesn't", with: .font(.boldSystemFont(ofSize: 34)))
    .add(.space)
    .add("that", with: .textColor(.blue))
    .add("either?")
    .add(.newLine)
    .build()

Requirements

  • Swift 5.3+
  • Xcode 12.0+
  • iOS 11.0+ / macOS 10.11+ / tvOS 11.0+

Installation

Select File > Swift Packages > Add Package Dependency and enter the repository URL.

https://github.com/kkiermasz/AttributedStringBuilder

Usage

Import the AttributedStringBuilder

import AttributedStringBuilder

And compose your awesome attributed string in one of previously introduced ways.

Demo

The playground demo can be found in the workspace associated with the project. remember that you have to build the library first.

License

AttributedStringBuilder is shared under the MIT license. See the LICENSE for more info.

Description

  • Swift Tools 5.3.0
View More Packages from this Author

Dependencies

Last updated: Thu Mar 14 2024 05:21:51 GMT-0900 (Hawaii-Aleutian Daylight Time)