@@ -48,11 +48,11 @@ final class AccessibilityElement {
48
48
}
49
49
50
50
func parent( ) -> Self ? {
51
- return self . value ( for: kAXParentAttribute )
51
+ return self . value ( for: . parent )
52
52
}
53
53
54
54
func role( ) -> String ? {
55
- return self . value ( for: kAXRoleAttribute )
55
+ return self . value ( for: . role )
56
56
}
57
57
58
58
func pid( ) -> pid_t ? {
@@ -62,24 +62,24 @@ final class AccessibilityElement {
62
62
}
63
63
64
64
func bringToFront( ) {
65
- if let isMainWindow = self . rawValue ( for: NSAccessibilityMainAttribute ) as? Bool , isMainWindow
65
+ if let isMainWindow = self . rawValue ( for: . main ) as? Bool , isMainWindow
66
66
{
67
67
return
68
68
}
69
69
70
70
AXUIElementSetAttributeValue ( self . elementRef,
71
- NSAccessibilityMainAttribute as CFString ,
71
+ NSAccessibilityAttributeName . main . rawValue as CFString ,
72
72
true as CFTypeRef )
73
73
}
74
74
75
75
// MARK: - Private functions
76
76
77
- static private func createSystemWideElement( ) -> Self {
77
+ private static func createSystemWideElement( ) -> Self {
78
78
return self . init ( elementRef: AXUIElementCreateSystemWide ( ) )
79
79
}
80
80
81
81
private func getPosition( ) -> CGPoint ? {
82
- return self . value ( for: kAXPositionAttribute )
82
+ return self . value ( for: . position )
83
83
}
84
84
85
85
private func set( position: CGPoint ) {
@@ -89,7 +89,7 @@ final class AccessibilityElement {
89
89
}
90
90
91
91
private func getSize( ) -> CGSize ? {
92
- return self . value ( for: kAXSizeAttribute )
92
+ return self . value ( for: . size )
93
93
}
94
94
95
95
private func set( size: CGSize ) {
@@ -98,25 +98,25 @@ final class AccessibilityElement {
98
98
}
99
99
}
100
100
101
- private func rawValue( for attribute: String ) -> AnyObject ? {
101
+ private func rawValue( for attribute: NSAccessibilityAttributeName ) -> AnyObject ? {
102
102
var rawValue : AnyObject ?
103
- let error = AXUIElementCopyAttributeValue ( self . elementRef, attribute as CFString , & rawValue)
103
+ let error = AXUIElementCopyAttributeValue ( self . elementRef, attribute. rawValue as CFString , & rawValue)
104
104
return error == . success ? rawValue : nil
105
105
}
106
106
107
- private func value( for attribute: String ) -> Self ? {
107
+ private func value( for attribute: NSAccessibilityAttributeName ) -> Self ? {
108
108
if let rawValue = self . rawValue ( for: attribute) , CFGetTypeID ( rawValue) == AXUIElementGetTypeID ( ) {
109
109
return type ( of: self ) . init ( elementRef: rawValue as! AXUIElement )
110
110
}
111
111
112
112
return nil
113
113
}
114
114
115
- private func value( for attribute: String ) -> String ? {
115
+ private func value( for attribute: NSAccessibilityAttributeName ) -> String ? {
116
116
return self . rawValue ( for: attribute) as? String
117
117
}
118
118
119
- private func value< T> ( for attribute: String ) -> T ? {
119
+ private func value< T> ( for attribute: NSAccessibilityAttributeName ) -> T ? {
120
120
if let rawValue = self . rawValue ( for: attribute) , CFGetTypeID ( rawValue) == AXValueGetTypeID ( ) {
121
121
return ( rawValue as! AXValue ) . toValue ( )
122
122
}
0 commit comments