Last active
March 19, 2019 23:10
-
-
Save NachoSoto/b3ffa949958aa8eb1432012e31004851 to your computer and use it in GitHub Desktop.
Extensions to simplify usage of accessibilityTraits in Swift 4.2:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
...What's wrong with
formUnion(_:)
?