CleanroomText is a Swift framework providing tools for working with strings and text.
CleanroomText is part of the Cleanroom Project from Gilt Tech.
This is the master
branch. It uses Swift 4.1 and requires Xcode 9.3 to compile.
Branch | Build status |
---|---|
master |
CleanroomText is distributed under the MIT license.
CleanroomText is provided for your use—free-of-charge—on an as-is basis. We make no guarantees, promises or apologies. Caveat developer.
The simplest way to integrate CleanroomText is with the Carthage dependency manager.
First, add this line to your Cartfile
:
github "emaloney/CleanroomText" ~> 3.0.0
Then, use the carthage
command to update your dependencies.
Finally, you’ll need to integrate CleanroomText into your project in order to use the API it provides.
Once successfully integrated, just add the following statement to any Swift file where you want to use CleanroomText:
import CleanroomText
See the Integration document for additional details on integrating CleanroomText into your project.
Pluralizer
s are used to represent multiple forms of a term intended to be used with specific quantities.
Here's an example of a Pluralizer
that represents two forms of the term "goose
":
let gooser = Pluralizer(singular: "goose", plural: "geese")
By calling the term(quantity: )
function, gooser
can then be used to select the appropriate form of the term for a given quantity:
let oneGoose = gooser.term(quantity: 1) // oneGoose will be "goose"
let threeGeese = gooser.term(quantity: 3) // threeGeese will be "geese"
You can also refer to the value passed to the term(quantity: )
function from within the terms passed to Pluralizer
's constructor:
let gooser = Pluralizer(singular: "one goose", plural: "{#} geese")
With this type of gooser
, the return values would be different:
let oneGoose = gooser.term(quantity: 1) // oneGoose will be "one goose"
let threeGeese = gooser.term(quantity: 3) // threeGeese will be "3 geese"
Normally, when specifying a quantity of zero, the Pluralizer
uses the plural form of the term:
let noGeese = gooser.term(quantity: 0) // noGeese will be "0 geese"
If needed, the zero-quantity form of the term can also be explicitly specified to the initializer:
let gooser = Pluralizer(singular: "one goose", plural: "{#} geese", none: "no geese")
With this type of gooser
, the return values would be different:
let noGeese = gooser.term(quantity: 0) // noGeese will be "no geese"
let oneGoose = gooser.term(quantity: 1) // oneGoose will be "one goose"
let threeGeese = gooser.term(quantity: 3) // threeGeese will be "3 geese"
For detailed information on using CleanroomText, API documentation is available.
The Cleanroom Project began as an experiment to re-imagine Gilt’s iOS codebase in a legacy-free, Swift-based incarnation.
Since then, we’ve expanded the Cleanroom Project to include multi-platform support. Much of our codebase now supports tvOS in addition to iOS, and our lower-level code is usable on macOS and watchOS as well.
Cleanroom Project code serves as the foundation of Gilt on TV, our tvOS app featured by Apple during the launch of the new Apple TV. And as time goes on, we'll be replacing more and more of our existing Objective-C codebase with Cleanroom implementations.
In the meantime, we’ll be tracking the latest releases of Swift & Xcode, and open-sourcing major portions of our codebase along the way.
CleanroomText is in active development, and we welcome your contributions.
If you’d like to contribute to this or any other Cleanroom Project repo, please read the contribution guidelines. If you have any questions, please reach out to project owner Paul Lee.
API documentation is generated using Realm’s jazzy project, maintained by JP Simard and Samuel E. Giddins.