<!--
{
  "availability" : [
    "iOS: 17.4.0 -",
    "iPadOS: 17.4.0 -",
    "macCatalyst: 17.4.0 -",
    "macOS: 14.4.0 -",
    "tvOS: 17.4.0 -",
    "visionOS: 1.1.0 -",
    "watchOS: 10.4.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "LightweightCodeRequirements",
  "identifier" : "/documentation/LightweightCodeRequirements/EntitlementsQuery",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "LightweightCodeRequirements"
    ],
    "preciseIdentifier" : "s:27LightweightCodeRequirements17EntitlementsQueryC"
  },
  "title" : "EntitlementsQuery"
}
-->

# EntitlementsQuery

A constraint that tests values in the entitlements dictionary associated with a process or code file.

```
class EntitlementsQuery
```

## Overview

Entitlements dictionaries use strings for keys. The value of each key could be a bool, integer, string, array or another dictionary. Arrays are homogenous.
Entitlements queries are a chain of operations that allow matching against arbitrarily nested values in the dictionary.

Example entitlements dictionary:

```xml
<dict>
    <key>com.apple.application-identifier</key>
    <string>com.apple.TextEdit</string>
    <key>com.apple.developer.ubiquity-container-identifiers</key>
    <array>
        <string>com.apple.TextEdit</string>
    </array>
    <key>com.apple.private.hid.client.event-dispatch.internal</key>
    <true/>
</dict>
```

Example query to match the first entitlement exactly

```swift
EntitlementsQuery.key("com.apple.application-identifier").matchSingle(com.apple.TextEdit)
```

Example query to match the second entitlement exactly.

```swift
EntitlementsQuery.key("com.apple.developer.ubiquity-container-identifiers").elementAtIndex(0).matchSingle("com.apple.TextEdit")
```

or to match the second entitlement less specifically

```swift
EntitlementsQuery.key("com.apple.developer.ubiquity-container-identifiers").match("com.apple.TextEdit")
```

The following query will detect the presence of the com.apple.private.hid.client.event-dispatch.internal key without checking its value.

```swift
EntitlementsQuery.key("com.apple.private.hid.client.event-dispatch.internal")
```

To match its value add a match() call to the chain.

```swift
EntitlementsQuery.key("com.apple.private.hid.client.event-dispatch.internal").match(true)
```

The following example demonstrate the keyPrefix query.

```swift
EntitlementsQuery.keyPrefix("com.apple.").match(true)
```

The keyPrefix query will match the “com.apple.application-identifier” only. Then the match query will fail because true does not match “com.apple.TextEdit”.

This constraint will cause a matching failure if the process or file being matched does not include entitlements.

## Topics

### Initializers

[`init(from: any Decoder) throws`](/documentation/LightweightCodeRequirements/EntitlementsQuery/init(from:))

Create a new instance by decoding from the given decoder

### Instance Methods

[`func elementAtIndex(Int64) -> EntitlementsQuery`](/documentation/LightweightCodeRequirements/EntitlementsQuery/elementAtIndex(_:))

Match against the specified index (0 based) in an array. Chain additional qualifiers to constrain the value of element.

[`func encode(to: any Encoder) throws`](/documentation/LightweightCodeRequirements/EntitlementsQuery/encode(to:))

Encodes this value into the given encoder

[`func key(String) -> EntitlementsQuery`](/documentation/LightweightCodeRequirements/EntitlementsQuery/key(_:)-swift.method)

Match the specified key in a nested dictionary

[`func keyPrefix(String) -> EntitlementsQuery`](/documentation/LightweightCodeRequirements/EntitlementsQuery/keyPrefix(_:)-swift.method)

Match the specified key prefix in a nested dictionary.

[`func match(String) -> EntitlementsQuery`](/documentation/LightweightCodeRequirements/EntitlementsQuery/match(_:)-5cqvy)

Match the specified string value against a string or an array of strings.

[`func match(Bool) -> EntitlementsQuery`](/documentation/LightweightCodeRequirements/EntitlementsQuery/match(_:)-5cw98)

Match the specified bool value against a bool value.

[`func match(Int64) -> EntitlementsQuery`](/documentation/LightweightCodeRequirements/EntitlementsQuery/match(_:)-6msza)

Match the specified Int64 against an integer or array of integers.

[`func matchPrefix(String) -> EntitlementsQuery`](/documentation/LightweightCodeRequirements/EntitlementsQuery/matchPrefix(_:))

Match the specified string prefix against a string value or array.

[`func matchPrefixSingle(String) -> EntitlementsQuery`](/documentation/LightweightCodeRequirements/EntitlementsQuery/matchPrefixSingle(_:))

Match the specified string prefix value against a string value (not an array).

[`func matchSingle(Int64) -> EntitlementsQuery`](/documentation/LightweightCodeRequirements/EntitlementsQuery/matchSingle(_:)-49kv7)

Match the specified Int64 value against an integer value (not an array).

[`func matchSingle(String) -> EntitlementsQuery`](/documentation/LightweightCodeRequirements/EntitlementsQuery/matchSingle(_:)-8ggh1)

Match the specified string against a string value (not an array).

[`func matchType(EntitlementsQuery.DataType) -> EntitlementsQuery`](/documentation/LightweightCodeRequirements/EntitlementsQuery/matchType(_:))

Matches the specified type against the current element.

### Type Methods

[`static func key(String) -> EntitlementsQuery`](/documentation/LightweightCodeRequirements/EntitlementsQuery/key(_:)-swift.type.method)

Match against the specified key name at the root of the entitlements dictionary.

[`static func keyPrefix(String) -> EntitlementsQuery`](/documentation/LightweightCodeRequirements/EntitlementsQuery/keyPrefix(_:)-swift.type.method)

Match the specified key prefix at the root of the entitlements dicitonary. Chain additional qualifiers to constrain the value of the key.

### Enumerations

[`enum DataType`](/documentation/LightweightCodeRequirements/EntitlementsQuery/DataType)

The types of elements allowed in entitlements dictionaries.

## Relationships

### Conforms To

[`Decodable`](/documentation/Swift/Decodable)

[`Encodable`](/documentation/Swift/Encodable)

[`OnDiskConstraint`](/documentation/LightweightCodeRequirements/OnDiskConstraint)

[`ProcessConstraint`](/documentation/LightweightCodeRequirements/ProcessConstraint)

[`Sendable`](/documentation/Swift/Sendable)

[`LaunchConstraint`](/documentation/LightweightCodeRequirements/LaunchConstraint)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

---

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)