```swift enum Operations: Int { case update case add case replace etc } enum Paths { case amount func pathValue(referenceId: String = "default") -> String { switch self { case amount: return "purchaseUnits[]/referenceId=\(referenceId ?? "default")/amount" case intent: return "intent" } } var acceptedOperations: [Operations] { switch self { case amount: return [.update] } } } let request = PatchOrderRequest(operation: .add, path: .amount) func patch(operation: Operation, path: Paths, value: Encodable) throws { guard path.acceptedOperations.contains(operation) else { throw <unacceptable operation error> } } 1. Path Enum -> correct path format 2. Path value with allowed / disallowed operations ``` ```swift patch(operation: .update, value: AmountObject) AmountObject: Patchable { pathValue: Path } protocol Patchable: Encodable { var pathValue: Path } func patch<T: Patchable>(operation: Operation, value: T) ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up