This is a small trick I use to compose complex accessibility labels/values when, for a UI component, some elements might not be in all its instances. An array of optional Strings, compact map, and join all elements by a separator, like a comma.

A tweet from Sebastiaan de With as an example. A tweet accessibility label is composed of many elements: Some tweets in home start with why you are seeing the tweet (Received new replies, someone liked it, based on your likes, someone retweeted, etc); the profile image is skipped; the user name is always part of the label; some users are verified; the user handle is not part of the label by default (but it can be enabled in Twitter's settings); the date is always there; and so is the text of the tweet; the tweets can have attachments (like a link, video or image with alt text); and a tweet can be a promoted one. Then we could compose the tweet value with the number of reactions (replies, likes and retweets), if any. We can create an array of optional strings where we'll be storing all these strings. Then we can do compactMap to remove nils, we could filter to check for empty strings and remove them too, and then we can join all these components by a separator character.

You may also find interesting...

When interacting with a button with VoiceOver, the accessibility label is repeated to the user. If you are playing some audio, it could be difficult to listen to it properly. To avoid that, you can add the .startsMediaSession accessibility trait.

@azzoor is the developer of the Braille Scanner It uses computer vision to locate the page and Machine Learning to match Braille to letters. You can see English letters above the braille, convert them to speech, copy and paste it... so cool!

You should convey important information in multiple modes, not just color. If you are still required to do so, at the very least you should complement that info with other modes, like symbols, if the user requested differentiation without color.

Created in Swift with Ignite.

Supporting Swift for Swifts