As you’ll know watchOS 2 allows you to create your own complications. One thing that really stood out to me is the idea of using providers instead of setting either text or images directly. There’s the abstract base class CLKTextProvider and CLKImageProvider that you provide (boom) to your complication. It’s the context in which the complication is rendered that decides on the actual on-screen representation of information.
So there’s this app I used to work on that needs to display prices a lot. And depending on the context where this prices is displayed it renders differently. Sounds similar to what the complication does. So in a grossly oversimplified example, let’s build something around providers using Swift:
This is our base provider. I think this close to actually showing the prices on screen it’s fine to be using Double. Otherwise use Int and divide by 100, always. Especially when crossing over system boundaries (APIs!) where you can never be sure of language specific rounding behaviour.
Next come our options on what we want to show using the new and great OptionSetType:
There’s a few things going on here. So let’s brake it down:
First we’re supplying the renderer with our NSNumberFormatters. Still I see people displaying prices without using formatters. Stop it, you’re doing it wrong. Even if your designers or you insist on really specific formats (though I’d always argue to rather go with the locale defaults), you can fine tune every last bit of the formatter to your liking.
Next up is the render method. You’ll probably want to really fine tune this part. Ideas that come to mind are a .Short format that removes decimal places if appropriate, drops certain parts of the price and things like glue words that can be prepended or formatted in a specific way. E.g. VAT: %s. Or maybe work out the reduction in price and highlight that. People love a bargain.