Last active
January 27, 2023 11:39
-
-
Save aliakhtar49/2f077c96488d5ab7747782ca4d2a40ed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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