<!--
{
  "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/CodeDirectoryHash",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "LightweightCodeRequirements"
    ],
    "preciseIdentifier" : "s:27LightweightCodeRequirements0B13DirectoryHashV"
  },
  "title" : "CodeDirectoryHash"
}
-->

# CodeDirectoryHash

A constraint that matches the hash of a code directory of a code file or of a running or launching process.

```
struct CodeDirectoryHash
```

## Overview

In the context of [`ProcessCodeRequirement`](/documentation/LightweightCodeRequirements/ProcessCodeRequirement) and [`LaunchCodeRequirement`](/documentation/LightweightCodeRequirements/LaunchCodeRequirement) this constraint matches the hash of the chosen code directory
for the running process, or the process the system is launching.

In the context of [`OnDiskCodeRequirement`](/documentation/LightweightCodeRequirements/OnDiskCodeRequirement) this constraint matches the hash of the code directory for the specified `SecStaticCodeRef` that best matches the current architecture.
The best match is different for processes running on Intel and Apple silicon, including an Intel process running on Apple silicon with Rosetta.
To reliably identify a code file using its code directory hash, use [`in(_:)`](/documentation/LightweightCodeRequirements/CodeDirectoryHash/in(_:)-912dv) and supply a list of the known code directory hash values.

## Topics

### Initializers

[`init(Data)`](/documentation/LightweightCodeRequirements/CodeDirectoryHash/init(_:))

Match against a single code directory hash.

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

Create a new instance by decoding from the given decoder

### Instance Methods

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

Encodes this value into the given encoder

### Type Aliases

[`typealias DataType`](/documentation/LightweightCodeRequirements/CodeDirectoryHash/DataType)

The basic input data type for this constraint: Data

[`typealias OutType`](/documentation/LightweightCodeRequirements/CodeDirectoryHash/OutType)

The type of this constraint: [`CodeDirectoryHash`](/documentation/LightweightCodeRequirements/CodeDirectoryHash)

### Type Methods

[`static func `in`([CodeDirectoryHash.DataType]) -> CodeDirectoryHash.OutType`](/documentation/LightweightCodeRequirements/CodeDirectoryHash/in(_:)-1kiuo)

Match against any of the code directory hashes in the provided list.

[`static func `in`(CodeDirectoryHash.DataType...) -> CodeDirectoryHash.OutType`](/documentation/LightweightCodeRequirements/CodeDirectoryHash/in(_:)-912dv)

Match against any of the code directory hashes in the provided list.

## Relationships

### Conforms To

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

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

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

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

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

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

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

---

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)