Quando eu clico no botão de cadastrar o paciente, o catch retorna um erro:
Houve um erro ao cadastrar paciente keyNotFound(CodingKeys(stringValue: "nome", intValue: nil), Swift.DecodingError.Context(codingPath: [], debugDescription: "No value associated with key CodingKeys(stringValue: \"nome\", intValue: nil) (\"nome\").", underlyingError: nil))
Já verifiquei se minhas CodingKeys estão de acordo com o retorno da API, mas não sei mais o que pode estar causando esse erro
struct Paciente
//
// Patient.swift
// Vollmed
//
// Created by Juan Carlos Parizotto da Silva on 24/11/25.
//
import Foundation
struct Patient: Identifiable, Codable {
let id: String?
let name: String
let email: String
let password: String
let cpf: String
let phoneNumber: String
let healthPlan: String
enum CodingKeys : String, CodingKey {
case id
case name = "nome"
case email
case password = "senha"
case cpf
case phoneNumber = "telefone"
case healthPlan = "planoSaude"
}
}
WebService
struct WebService {
private let baseURL = "http://localhost:3000"
private let imageCache = NSCache<NSString, UIImage>()
func registerPatient(_ patient: Patient) async throws -> Patient? {
let endpoint = baseURL + "/paciente"
guard let url = URL(string: endpoint) else {
print("Erro ao buscar URL")
return nil
}
let jsonData = try JSONEncoder().encode(patient)
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = jsonData
let (data, _) = try await URLSession.shared.data(for: request)
let patient = try JSONDecoder().decode(Patient.self, from: data)
return patient
}
[...]