Skip to content

Instantly share code, notes, and snippets.

@pietrorea
Created July 2, 2021 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pietrorea/a47f348cb25f2aae71d9f916e8b5326d to your computer and use it in GitHub Desktop.
Save pietrorea/a47f348cb25f2aae71d9f916e8b5326d to your computer and use it in GitHub Desktop.
Alamofire 5.43 `responseDecodable` example
static func load(_ entityId: Int, completion: @escaping ( (SampleServiceResponse?) -> Void)) {
let urlString = "https://api.sweetpeamobile.com/v1/sampleService?locationId=\(locationId)"
AF.request(urlString).responseDecodable(of: SampleServiceResponse.self) { response in
switch response.result {
case .success(let decodedResponse):
completion(decodedResponse)
case .failure(let error):
print("Networking error: \(error.localizedDescription)")
completion(nil)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment