Pluot
At Plum we use a lot of NSAttributedString’s. This gives us much greater control over the appearance of the text.
However, NSAttributedString’s API isn’t the most lightweight and constructing a paragraph of text can add up to a reasonably sized mountain of code. It can be quite the cognitive challenge to picture what the text will end up looking like.
Introducing Pluot
Pluot is a lightweight library for constructing NSAttributedString’s.
We built Pluot with 2 aims:
1. To have a lightweight API that is easy to read.
2. To be able to set default styles; an engineer shouldn’t have to needlessly repeat themselves.
Example
To use Pluot; firstly initialise an instance passing it a list of default styles:
let pluot = Pluot(
.font(.systemFont(ofSize: 24.0)),
.color(.red),
.paragraph({ (style) in
style.alignment = .center
})
)
Then, to create a NSAttributedString:
// Some kind of value.
let value = 1000// Build the string.
pluot.build(
.string(“Hello. This is a test”),
.space,
.string(UUID().uuidString, [.font(.systemFont(ofSize: 24.0, weight: .bold)), .color(.blue)]),
.if(value > 99, [
.string(“So true”)
], else: [
.string(“So false”)
])
)
// => `NSAttributedString`
Check It Out!
Swift PM
dependencies: [
.package(url: “https://github.com/withplum/Pluot", from: “0.12.0”)
]
Github
https://github.com/withplum/Pluot
We’re Hiring
Join the iOS team in Athens (GR), London (UK), Bath (UK) or remote (2+/- hours UK time)!