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
βpatch(operation: .update, value: AmountObject)
β
βAmountObject: Patchable {
β pathValue: Path
β}
β
βprotocol Patchable: Encodable {
β var pathValue: Path
β}
β
βfunc patch<T: Patchable>(operation: Operation, value: T)
user image URL
Oct 4, 2023iOS:
Oct 2, 2023Auth Latency Reporting
Sep 26, 2023Networking headers typed responses / result method networkingClient.createAccessToken(client: "SSS") { result in switch result { case .succes(let model): //
Sep 10, 2021or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up