My API returns the following JSON (an array of [CustomClass]):
[{
"name": "Name A",
"startingDate": "2018-01-01",
"duration": 4
},
{
"name": "Name B",
"startingDate": "2018-01-01",
"duration": 4
}
]
I'm using Alamofire to make the request and then parsing the JSON:
static func test(parametersGet:Parameters, completion: @escaping ([CustomStruct]?, Error?) -> Void ) {
Alamofire.request(API.test, parameters: parametersGet).validate().responseJSON { response in
switch response.result {
case .success:
if let json = response.result.value {
let workoutCards = json as! [CustomStruct]
completion(workoutCards, nil)
}
case .failure(let error):
completion(nil, error)
}
}
}
CustomStruct it's simply a Codable struct with those keys.
I get the following error: "Could not cast value of type '__NSDictionaryI' to 'Project.CustomStruct'". How can I parse the JSON?