Created
April 19, 2019 02:36
-
-
Save nil-biribiri/85f012afa320d5a7a0681b7c72eecd03 to your computer and use it in GitHub Desktop.
Auto create accessibilityIdentifier of view elements by using name "#ClassName.#ViewElementName".
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
protocol Accessible { | |
func generateAccessibilityIdentifiers() | |
} | |
extension Accessible { | |
func generateAccessibilityIdentifiers() { | |
#if DEBUG | |
let mirror = Mirror(reflecting: self) | |
for child in mirror.children { | |
if | |
let view = child.value as? UIView, | |
let identifier = child.label?.replacingOccurrences(of: ".storage", with: "") { | |
view.accessibilityIdentifier = "\(type(of: self)).\(identifier)" | |
} | |
} | |
#endif | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment