struct PredicateCodableConfiguration: CustomDebugStringConvertible, Sendable

<aside> πŸ’‘ ν•΄λ‹Ή configuration으둜 CodableWithConfiguration ν”„λ‘œν† μ½œ μ€€μˆ˜μ„±μ„ μΆ”κ°€ν•˜λ©΄ encoding/decoding μž‘μ—…μ‹œ predicate이 포함할 수 μžˆλŠ” νƒ€μž… 및 keypathλ₯Ό μ œν•œν•  수 μžˆλ‹€.

<aside> <img src="/icons/list_blue.svg" alt="/icons/list_blue.svg" width="40px" /> λͺ©μ°¨

</aside>

</aside>

λ‹€μŒκ³Ό 같이 μž‘μ„±ν•΄λ³Ό 수 μžˆλ‹€:

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**)
    }
}

μœ„ μ˜ˆμ œμ—μ„œ predicate ν”„λ‘œνΌν‹°κ°€ configurationμ—μ„œ ν—ˆμš©ν•˜μ§€ μ•Šμ€ νƒ€μž… λ˜λŠ” keypathλ₯Ό 포함할 경우, encoding/decoding μž‘μ—…μ‹œ μ—λŸ¬λ₯Ό λ˜μ§„λ‹€.

API

생성

νƒ€μž… 및 keypath의 ν—ˆμš©/λΉ„ν—ˆμš© μ„€μ •

λͺ¨μ•„보기

init()
static let standardConfiguration: PredicateCodableConfiguration

mutating func allowType(_ type: Any.Type, identifier: String? = nil)
mutating func disallowType(_ type: Any.Type)

mutating func allowPartialType(_ type: Any.Type, identifier: String)
mutating func disallowPartialType(_ type: Any.Type)

mutating func allowKeyPath(_ keyPath: AnyKeyPath, identifier: String)
mutating func disallowKeyPath(_ keyPath: AnyKeyPath)

mutating func allowKeyPathsForPropertiesProvided<T>(by type: T.Type, recursive: Bool = false) where T: PredicateCodableKeyPathProviding
mutating func disallowKeyPathsForPropertiesProvided<T>(by type: T.Type, recursive: Bool = false) where T: PredicateCodableKeyPathProviding

mutating func allow(_ other: PredicateCodableConfiguration)

// conforming CustomDebugStringConvertible protocol
var debugDescription: String

참고자료