PredicateCodableConfiguration
A specification of the expected types and key paths found in an archived predicate.
Declaration
struct PredicateCodableConfigurationOverview
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.
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
Allowing types and key paths
allow(_:)allowKeyPathsForPropertiesProvided(by:recursive:)allowPartialType(_:identifier:)allowType(_:identifier:)