---
title: Day 15
author: Daniel Devesa Derksen-Staats
date: 2022-06-02 09:00
tags: VoiceOver, iOS
categories: ["Accessibility"]
series: ["365 Days iOS Accessibility"]
image: /Images/365DaysIOSAccessibility/image180.jpg
---

Tip for abbreviations. Something like "3h 24m" will be read by VoiceOver as "3 h 24 meters". Formatters can help. DateComponentsFormatter with a "spellOut" units style will give you a more suitable label: "three hours, twenty-four minutes"

![Code shows how you can create a DateComponentsFormatter, configure its allowed units and the units style with spell out, and you can get a human readable string representing the time from it, by passing a time interval.](/Images/365DaysIOSAccessibility/image180.jpg)

[Example code in the image:](https://gist.github.com/dadederk/579dc93af9ec2feb225953781640ad87)

```swift
let dailyAverageLabel = UILabel()
let abbreviatedReadableFormatter = DateComponentsFormatter()

abbreviatedReadableFormatter.allowedUnits = [.hour, .minute]
abbreviatedReadableFormatter.unitsStyle = .spellOut

let abbreviatedReadableDuration = abbreviatedReadableFormatter.string(from: 12240)

dailyAverageLabel.accessibilityLabel = abbreviatedReadableDuration
```

Some useful links:
* [Date Components Formatter:](https://developer.apple.com/documentation/foundation/datecomponentsformatter)
* [Units Style:](https://developer.apple.com/documentation/foundation/datecomponentsformatter/unitsstyle-swift.enum)

By the way! Formatters are also great for localisation.
