Skip to content

Instantly share code, notes, and snippets.

@NachoSoto
Last active March 19, 2019 23:10
Show Gist options
  • Save NachoSoto/b3ffa949958aa8eb1432012e31004851 to your computer and use it in GitHub Desktop.
Save NachoSoto/b3ffa949958aa8eb1432012e31004851 to your computer and use it in GitHub Desktop.
Extensions to simplify usage of accessibilityTraits in Swift 4.2:
// Extensions to simplify usage of accessibilityTraits in Swift 4.2:
public func |= (traits: inout UIAccessibilityTraits, other: [UIAccessibilityTraits]) {
for o in other {
traits |= o
}
}
public func |= (traits: inout UIAccessibilityTraits, other: UIAccessibilityTraits) {
// From: https://swift.org/migration-guide-swift4.2/#known-migration-issues
traits = UIAccessibilityraits(rawValue: traits.rawValue | other.rawValue)
}
// Before Swift 4.2:
view.accessibilityTraits |= UIAccessibilityTraitButton
// In Swift 4.2:
view.accessibilityTraits = UIAccessibilityTraits(rawValue: view.accessibilityTraits.rawValue | UIAccessibilityTraits.header.rawValue)
// Example usage:
view.accessibilityTraits |= [.header, .link]
@matt-curtis
Copy link

...What's wrong with formUnion(_:)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment