NSAttributedStringBuilder 0.1

NSAttributedStringBuilder 0.1

Maintained by Vincent Pradeilles.



  • By
  • Vincent Pradeilles

NSAttributedStringBuilder

platforms pod Carthage compatible

Context

NSAttributedStringBuilder is a Swift micro framework that leverages Function Builders to implement syntactic sugar that lets you intuitively compose attributed strings.

Instead of writing:

let attributedString = NSMutableAttributedString(string: "Hello", attributes: [.font: UIFont.systemFont(ofSize: 24), .foregroundColor: UIColor.red])
attributedString(NSAttributedString(string: " world!", attributes: [.font: UIFont.systemFont(ofSize: 20), .foregroundColor: UIColor.orange]))

You can now write:

let attributedString = NSAttributedString.composing {
    NSAttributedString(string: "Hello", attributes: [.font: UIFont.systemFont(ofSize: 24), .foregroundColor: UIColor.red])
    NSAttributedString(string: " world!", attributes: [.font: UIFont.systemFont(ofSize: 20), .foregroundColor: UIColor.orange])
}

Requirements

Xcode 11+ & Swift 5.1

Installation

CocoaPods

Add the following to your Podfile:

pod "NSAttributedStringBuilder"

Carthage

Add the following to your Cartfile:

github "vincent-pradeilles/NSAttributedStringBuilder"

Author