您好,我所有的代码都应检测到重点关注的应用程序,在下一部分中,我想在检测到的应用程序的字段中插入一些文本,但是运行此代码时出现错误,我无法解决它:>
import Foundation
func getFocusedApp() -> AXUIElement? {
var output: AXUIElement? = nil
let systemWideElement: AXUIElement = AXUIElementCreateSystemWide()
let kAXFocusedApplication : CFString! = "AXFocusedApplication" as CFString
let focusedElementPtr : UnsafeMutablePointer<CFTypeRef?> = UnsafeMutablePointer.allocate(capacity: 1)
let error : AXError = AXUIElementCopyAttributeValue(systemWideElement, kAXFocusedApplication, focusedElementPtr)
if let ue = focusedElementPtr.memory {
output = ue.takeUnretainedValue() as AXUIElement
}
else {
print(error)
}
focusedElementPtr.deallocate()
return output
}
print(getFocusedApp())
这是错误:
error: value of type 'UnsafeMutablePointer<CFTypeRef?>' (aka 'UnsafeMutablePointer<Optional<AnyObject>>') has no member 'memory'
if let ue = focusedElementPtr.memory {
顺便说一句。我不是SWIFT开发人员,所以为所有错误感到抱歉。