CleanroomText
CleanroomText is a Swift framework providing tools for working with strings and text.
CleanroomText is part of the Cleanroom Project from Gilt Tech.
Swift 2.2 compatibility
The master
branch of this project is Swift 2.2 compliant and therefore requires Xcode 7.3 or higher to compile.
License
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.
Adding CleanroomText to your project
You’ll need to integrate CleanroomText into your project in order to use the API it provides. You can choose:
- Manual integration, wherein you embed CleanroomText’s Xcode project within your own, or
- Using the Carthage dependency manager to build a framework that you then embed in your application.
Once integrated, just add the following import
statement to any Swift file where you want to use CleanroomText:
import CleanroomText
Using CleanroomText
Pluralizer
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 termForQuantity()
function, gooser
can then be used to select the appropriate form of the term for a given quantity:
let oneGoose = gooser.termForQuantity(1) // oneGoose will be "goose"
let threeGeese = gooser.termForQuantity(3) // threeGeese will be "geese"
Quantity Replacement
You can also refer to the value passed to the termForQuantity()
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.termForQuantity(1) // oneGoose will be "one goose"
let threeGeese = gooser.termForQuantity(3) // threeGeese will be "3 geese"
Zero Quantities
Normally, when specifying a quantity of zero, the Pluralizer
uses the plural form of the term:
let noGeese = gooser.termForQuantity(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.termForQuantity(0) // noGeese will be "no geese"
let oneGoose = gooser.termForQuantity(1) // oneGoose will be "one goose"
let threeGeese = gooser.termForQuantity(3) // threeGeese will be "3 geese"
API documentation
For detailed information on using CleanroomText, API documentation is available.
About
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 Mac OS X 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.
Contributing
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.
Acknowledgements
API documentation for CleanroomText is generated using Realm’s jazzy project, maintained by JP Simard and Samuel E. Giddins.