CLKTextProvider is part of ClockKit in watchOS 2. It's an abstract base class of a family of classes that allow you to provide text content for a complication on Apple Watch. Visual space on the Apple Watch's screen is so constrained, that Apple has created a whole suite of classes for gracefully degrading the way values are displayed in complications, depending on how much space is available.
Essentially, you tell the class the value you want displayed, and the system handles formatting and best fitting the content for the constraints of the complication it's included in.
import ClockKit
let now = NSDate()
let units : NSCalendarUnit = [ .Weekday, .Month, .Day ]
let textProvider = CLKDateTextProvider(now, units)
// textProvider will now render one
// of these strings, depending on
// the environment its in:
// "Monday, June 22"
// "Mon, Jun 22"
// "Jun 22"
// "22"
In addition, ClockKit also contains text providers for many common values you might want to include in a complication such as:
- Dates/times like "Monday June 22" or "10:09"
- Relative dates/times including 3 different styles: Natural ("2HRS 11MINS") , Timer ("09:42"), and Offset ("+31 MINUTES")
- Time intervals like "1:00-2:30PM"
There's also a generic ‘simple' text provider for gracefully degrading your own custom text content.
CLKTextProvider (as well as the rest of ClockKit) is sadly only available in watchOS at the moment. It's such a great little set of utilities, here's hoping it makes it way into iOS and OS X at some point!