<!--
{
  "availability" : [
    "Xcode: 16.3.0 -",
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "XCUIAutomation",
  "identifier" : "/documentation/XCUIAutomation/XCUIApplication/state-swift.property",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "XCUIAutomation"
    ],
    "preciseIdentifier" : "c:objc(cs)XCUIApplication(py)state"
  },
  "title" : "state"
}
-->

# state

The most recent state of the application.

```
var state: XCUIApplication.State { get }
```

## Discussion

The system monitors the app to update this property as the app’s state changes. Consequently, the system updates the value of this property asynchronously.

The system makes the following guarantees:

- When [`launch()`](/documentation/XCUIAutomation/XCUIApplication/launch()) and [`activate()`](/documentation/XCUIAutomation/XCUIApplication/activate()) return successfully, the state of the application is [`XCUIApplication.State.runningForeground`](/documentation/XCUIAutomation/XCUIApplication/State-swift.enum/runningForeground). An exception to this is launching or activating a macOS agent application with <doc://com.apple.documentation/documentation/BundleResources/Information-Property-List/LSUIElement> set in its `Info.plist `file. This kind of application never gains foreground status and its state is [`XCUIApplication.State.runningBackground`](/documentation/XCUIAutomation/XCUIApplication/State-swift.enum/runningBackground) instead.
- When [`terminate()`](/documentation/XCUIAutomation/XCUIApplication/terminate()) returns successfully, the state of the application is [`XCUIApplication.State.notRunning`](/documentation/XCUIAutomation/XCUIApplication/State-swift.enum/notRunning).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)