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...

Accessibility Labels are not just for VoiceOver, and Accessibility User Input Labels are not just for Voice Control. The latter will also help Full Keyboard Access users to find elements on the screen by different names. Good API design!

@azzoor has this great video with some advice on how to set up your device for testing accessibility and a ton of tips will get you testing effectively in no time. https://m.youtube.com/watch?v=Ca1H6wF348g&feature=youtu.be

Sometimes your UI will just not scale for large text sizes. Simple changes, for large sizes, like disposing elements vertically instead of horizontally, reducing the number of columns, and allowing more lines of text, can do the trick most times.

Created in Swift with Ignite.

Supporting Swift for Swifts