In Objective-C accessibility traits are a bitmask. Some devs find tricky to work with them using bitwise operations. In Swift they conform to the OptionSet protocol that conforms to SetAlgebra. That means you can simply insert/remove traits.

Code shows how with Objective-C you need to use bitwise operations to operate with accessibility traits. Bitwise AND (|) for adding traits and bitwise NOT (& ~) to remove them. Accessibility trait none is useful to remove all traits. In Swift, the traits conform to the OptionSet protocol that conforms to SetAlgebra, so you can do things like: insert, remove, formUnion, intersection, isSubset, etc.

You may also find interesting...

When building custom components, or if not relying on UIControl's attributes to configure state, it can be easy to forget to specify the right accessibility traits. These are indispensable for a good experience with VoiceOver, Switch Control...

Toggles or UISwitches are often found separated from the label that precedes (and describes) them; with an unclear label; missing a value, trait, or hint; or even not being actionable at all.

You can add an observer to listen for changes in the content size category, in case it is more convenient than overriding traitCollectionDidChange(_:).

Created in Swift with Ignite.

Supporting Swift for Swifts