Skip to content

Instantly share code, notes, and snippets.

@aliakhtar49
Last active January 27, 2023 11:39
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 aliakhtar49/2f077c96488d5ab7747782ca4d2a40ed to your computer and use it in GitHub Desktop.
Save aliakhtar49/2f077c96488d5ab7747782ca4d2a40ed to your computer and use it in GitHub Desktop.
private func commonInit() {
// API Hitting
fetchPaymentInfoResponse { [weak self] paymentResponse in
// Data Preparation / Business logic
let entity = PaymentInfoView.Entity(
paymentLogo: paymentResponse!.logo,
paymentDetail: paymentResponse!.details,
paymentTitleValue: paymentResponse!.title
)
self.state = .info(entity)
self.setupView()
}
}
func fetchPaymentInfoResponse(completion: @escaping (PaymentInfoResponse?) -> Void) {
let url = URL(string: "https://baseurlpath.com/paymentInfo/componentId")!
let task = URLSession.shared.dataTask(with: url) {(data, response, error) in
// Expected Response
// let json = """
// {
// "logo": "bx-visa",
// "last4": "4242",
// "title": "Visa Card"
// }
// """
// Parsing logic
let response = try! JSONDecoder().decode(PaymentInfoResponse.self, from: data!)
completion(response)
}
task.resume()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment