AXKit is a lightweight Swift library that generates accessibility identifiers for your UIKit views. It was written to simplify automated UI testing by providing consistent, structured identifiers for views.
- Automatically generates accessibility identifiers for any UIKit element.
- Supports hierarchical identifiers including index, indexPath, and purpose.
- Lightweight and simple to integrate.
- Only active in DEBUG builds, ensuring no impact on production apps.
class MyViewController: UIViewController, Accessible {
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var actionButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
setupAccessibilityIdentifiers()
}
}let info = AccessibilityInfo(indexPath: IndexPath(row: 0, section: 1),
purpose: "testing")
myViewController.setupAccessibilityIdentifiersForViewProperties(withAccessibilityInfo: info)This will automatically assign accessibility identifiers to all UIView properties in your class based on their property name and optional metadata:
<MyViewController>.<propertyName>[.s<Section>-r<Row>][.<Index>][.<Purpose>]
For a button property named actionButton in section 1, row 0 with purpose "testing", the resulting identifier will be:
MyViewController.actionButton.s1-r0.testing
Identifiers are only generated in DEBUG builds.
The library uses reflection (Mirror) to automatically find all UIView properties in your class.
Useful for UI testing, especially with XCTest.
AXKit is available under the MIT license. See the LICENSE file for more info.
Dmytro Skorokhod