// A hosted SwiftUI view builds its accessibility tree only while something // reads it — VoiceOver, or UI automation. A unit test that walks the tree of // a page it hosts (a deck's counter, a note's page label, Select all) on a // fresh job simulator, where neither runs, finds the hosting view's one // empty node. The test turns the simulator's automation accessibility on for // its own process first, as an XCUITest run would; nothing in the app reads it. #if os(iOS) import Darwin import UIKit enum HostedAccessibility { /// Turns automation accessibility on for this process, once; false when the simulator's library will not say how. @MainActor @discardableResult static func enable() -> Bool { if enabled { return true } guard let library = dlopen("/usr/lib/libAccessibility.dylib", RTLD_NOW), let set = dlsym(library, "_AXSSetAutomationEnabled") else { return false } unsafeBitCast(set, to: (@convention(c) (Int32) -> Void).self)(1) enabled = true return true } @MainActor private static var enabled = false } #endif