Skip to content

Instantly share code, notes, and snippets.

@nil-biribiri
Created April 19, 2019 02:36
Show Gist options
  • Save nil-biribiri/85f012afa320d5a7a0681b7c72eecd03 to your computer and use it in GitHub Desktop.
Save nil-biribiri/85f012afa320d5a7a0681b7c72eecd03 to your computer and use it in GitHub Desktop.
Auto create accessibilityIdentifier of view elements by using name "#ClassName.#ViewElementName".
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