Skip to content
µframework for Attributed strings.
Swift Ruby Objective-C
Branch: master
Clone or download
Nirma Merge pull request #66 from Nirma/fix/travis-ci-xcode-10-2
Fix travis CI settings to use XCode10.2 image
Latest commit 133d7c3 Apr 14, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
Attributed.xcodeproj Project modernization changes for swift 5 Apr 8, 2019
Attributed Project modernization changes for swift 5 Apr 8, 2019
AttributedTests Update copyright to 2019 Feb 9, 2019
.gitignore Initial Implementation Dec 26, 2016
.swift-version Update cocoapods info for swift 5 Apr 8, 2019
.swiftlint.yml [swiftlint] disable rule line_lenght. Feb 9, 2019
AttributedLib.podspec Update cocoapods info for swift 5 Apr 8, 2019 Update Oct 30, 2017
LICENSE Update LICENSE Jul 20, 2017 Update Apr 13, 2019


Build Status CodeCov Swift 5.0 CocoaPods compatible Carthage compatible License

µframework for Attributed strings.

What is Attributed?

Attributed aims to be a drop in replacement to the current version of the NSAttributedString API.

The NSAttributedString interface has a few shortcomings. If you donʼt know the key and type of value needed to set a certain attribute, you have to spend time checking documentation. Another concern is safety: passing a dictionary of type [String: Any] to the constructor of NSAttributedString is a potential crash at runtime waiting to happen.

Attributed provides developers a nicer alternative by extending the current NSAttributedString interface with a fluent, strongly typed, and easy to use API.


  • Create NSAttributedString instances with a strongly typed, simple, and fluid interface
  • Combine NSAttributedStrings with +
  • Partially apply Attributes to parts of an NSAttributedString by providing a Range

Donʼt see a feature you need?

Feel free to open an issue requesting the feature you want or send over a pull request!


Creating a new NSAttributedString by closure composition

"This is not a string".at.attributed {
  return $0.foreground(color: .red)
           .font(UIFont(name: "Chalkduster", size: 24.0)!)

Creating a new NSAttributedString by passing an attributes object

First create an Attributes object:

let attributes = Attributes {
    return $0.foreground(color: .red)
             .font(UIFont(name: "Chalkduster", size: 24.0)!)

then simply apply the Attributes to a String:

"Hello".at.attributed(with: attributes)

Combining NSAttributedString with +

This library defines an concatenation operator + for concatentating instances of NSAttributedString. + works with NSAttributedString no different than it does for String. This can be useful for combining NSAttributedStrings with different attributes to produce the desired effect without having to specify ranges to apply different attributes to.

let bodyAttributes = Attributes { 
    return $0.foreground(color: .purple)
             .font(UIFont(name: "Noteworthy-Light", size: 20.0)!)

let authorAttributes = bodyAttributes.foreground(color: .black)

"I think theres something strangely musical about noise.".at.attributed(with: bodyAttributes)
+ "\n  - Trent Reznor".at.attributed(with: authorAttributes)



If you use Carthage to manage your dependencies, simply add Attributed to your Cartfile:

github "Nirma/Attributed"

If you use Carthage to build your dependencies, make sure you have added Attributed.framework to the "Linked Frameworks and Libraries" section of your target, and have included Attributed.framework in your Carthage framework copying build phase.


If you use CocoaPods to manage your dependencies, simply add Attributed to your Podfile:

pod 'AttributedLib'


  • Xcode 9.0
  • Swift 4.0+


Contributions are more than welcome!


Attributed is free software, and may be redistributed under the terms specified in the LICENSE file.

You can’t perform that action at this time.