How to handle UnsafePointer?>

前端 未结 1 340
逝去的感伤
逝去的感伤 2021-01-24 14:45

How do I call the following function:

func AXUIElementCopyAttributeNames(element: AXUIElement!, names: UnsafePointer?>) -> AXErro

1条回答
  •  清酒与你
    2021-01-24 15:25

    I am a little bit guessing (because I have no experience with the Accessibility functions), but from the function declaration it should work like this:

    let element: AXUIElementRef = ...
    
    var ptr : Unmanaged? = nil
    let error = AXUIElementCopyAttributeNames(element, &ptr)
    if error == AXError(kAXErrorSuccess) {
        let names = ptr!.takeRetainedValue() // gives a CFArray
        // ...
    }
    

    Update for Swift 3 (untested):

    let element: AXUIElement = ...
    
    var cfArray: CFArray?
    let error = AXUIElementCopyAttributeNames(element, &cfArray)
    if error == .success, let names = cfArray as? [String] {
        // names is [String] array ...
    }
    

    0 讨论(0)
提交回复
热议问题