<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macCatalyst: 17.0.0 -",
    "macOS: 14.0.0 -",
    "tvOS: 17.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/PredicateCodableConfiguration",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation29PredicateCodableConfigurationV"
  },
  "title" : "PredicateCodableConfiguration"
}
-->

# PredicateCodableConfiguration

A specification of the expected types and key paths found in an archived predicate.

```
struct PredicateCodableConfiguration
```

## Overview

Use this configuration when encoding and decoding a predicate to restrict what that predicate can contain.  If a predicate contains data types or keypaths that aren’t allowed by the configuration, the encoding or decoding process throws an error.

```swift
var configuration = PredicateCodableConfiguration.standardConfiguration
configuration.allowType(Message.self, identifier: "MyApp.Message")
configuration.allowType(Person.self, identifier: "MyApp.Person")
configuration.allowKeyPath(\Message.sender, identifier: "MyApp.Message.sender")
configuration.allowKeyPath(\Person.firstName, identifier: "MyApp.Person.firstName")
configuration.allowKeyPath(\Person.lastName, identifier: "MyApp.Person.lastName")

struct MyRequest: Codable {
    let predicate: Predicate<Message>
    
    func encode(to encoder: Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(predicate, forKey: .predicate, configuration: configuration)
    }
    
    init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)
        predicate = try container.decode(Predicate<Message>.self, forKey: .predicate, configuration: configuration)
    }
}
```

## Topics

### Creating a configuration

[`init()`](/documentation/Foundation/PredicateCodableConfiguration/init())

[`standardConfiguration`](/documentation/Foundation/PredicateCodableConfiguration/standardConfiguration)

### Allowing types and key paths

[`allow(_:)`](/documentation/Foundation/PredicateCodableConfiguration/allow(_:))

[`allowKeyPathsForPropertiesProvided(by:recursive:)`](/documentation/Foundation/PredicateCodableConfiguration/allowKeyPathsForPropertiesProvided(by:recursive:))

[`allowPartialType(_:identifier:)`](/documentation/Foundation/PredicateCodableConfiguration/allowPartialType(_:identifier:))

[`allowType(_:identifier:)`](/documentation/Foundation/PredicateCodableConfiguration/allowType(_:identifier:))

### Disallowing types and key paths

[`disallowKeyPathsForPropertiesProvided(by:recursive:)`](/documentation/Foundation/PredicateCodableConfiguration/disallowKeyPathsForPropertiesProvided(by:recursive:))

[`disallowPartialType(_:)`](/documentation/Foundation/PredicateCodableConfiguration/disallowPartialType(_:))

[`disallowType(_:)`](/documentation/Foundation/PredicateCodableConfiguration/disallowType(_:))

### Instance Methods

[`allowKeyPath(_:identifier:)`](/documentation/Foundation/PredicateCodableConfiguration/allowKeyPath(_:identifier:))

[`disallowKeyPath(_:)`](/documentation/Foundation/PredicateCodableConfiguration/disallowKeyPath(_:))

## Relationships

### Conforms To

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

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

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

---

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)