Thanks to @VishalPatel, i figured out how to do it:
class TreatmentsManager: ObservableObject {
@Published var treatments = [Treatment]()
func testAlamofire() {
AF.request("http://dermaservice.theappmaster.com/Tratamiento.ashx").response { response in
switch response.result {
case .success(let value):
do {
let results = try JSONDecoder().decode(TreatmentList.self, from: value!)
DispatchQueue.main.async {
self.treatments = results.Tratamientos
}
} catch {
print(error)
}
case .failure(let error):
print(error)
}
}
}
}
Where TreatmentList is a struct containing [Treatments].
So there is not need to use SwiftyJSON
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…