On running the following code:

let pid = getAppPid()
let AXApp = AXUIElementCreateApplication(pid)

var children: CFTypeRef?
let returnVal = AXUIElementCopyAttributeValue(AXApp,
kAXChildrenAttribute as CFString, &children)

  • AXApp gets created successfully

However

I've seen code on stack overflow and elsewhere using exactly the same method as I am.

What am I missing.

I am using Xcode 9/Swift 4 on MacOS High Sierra.

EDIT:

I should add that Xcode has accessibility permissions, and I am able to successfully do other stuff that requires accessibility permission like CGEvent.tapCreate() to monitor global keyboard events etc.