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
import UIKit | |
final class FirstViewUI: UIView { | |
var names = | |
[ | |
"first", | |
"seo", | |
"psum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the in", | |
"four", |
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
public protocol PaymentDetailsViewLoadable { | |
/// Communication with client | |
var output: AnyPublisher<PaymentDetailLoadableOutput, Never> { get } | |
/// render payment details view into the view provided | |
func renderView( | |
componentId: String, | |
into containerView: UIView | |
) | |
} |
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) |
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
// Step 1 : Initialize View and interface | |
private let paymentDetailsInjector: PaymentDetailsViewLoadable = PaymentDetailsViewLoader() | |
private let paymentDetailsViewContainer: UIView = UIView() | |
// Step 2 : listen call backs and load view | |
private func commonInit() { | |
paymentDetailsInjector.renderView( | |
componentId: "123", | |
into: paymentDetailsViewContainer | |
) |
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
func configureSkeltonView() { | |
[1...4].forEach { _ in | |
scrollStackViewContainer.addArrangedSubview(OrderTrackingSkeletonView()) | |
} | |
} | |
func configureContainerView(response: OrderTrackingResponse) { | |
let paymentInfoView = PaymentInfoView(entity: ...) | |
let orderSummaryTitleViews = OrderSummaryTitleView(entity: ...) | |
let deliveryAddressView = DeliveryAddressView(entity: ...) |
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
final class OrderTrackingViewController: UIViewController { | |
override func viewDidLoad() { | |
// Initial show loading view | |
ui.configureSkeltonView() | |
repo.fetchOrderTrackingResponse { [weak self] orderResponse in | |
// Response receive render whole screen with data | |
self?.ui.configureContainerView(response: orderResponse!) | |
} | |
} | |
} |
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
func downloadImageAndMetadata(imageNumber: Int) async throws -> DetailedImage { | |
return try await withCheckedThrowingContinuation({ | |
(continuation: CheckedContinuation<DetailedImage, Error>) in | |
downloadImageAndMetadata(imageNumber: imageNumber) { image, error in | |
if let image = image { | |
continuation.resume(returning: image) | |
} else { | |
continuation.resume(throwing: error!) | |
} | |
} |
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
let metadataUrl = URL(string: "https://www.andyibanez.com/fairesepages.github.io/tutorials/async-await/part1/\(imageNumber).json")! | |
let metadataTask = URLSession.shared.dataTask(with: metadataUrl) { data, response, error in | |
guard let data = data, let metadata = try? JSONDecoder().decode(ImageMetadata.self, from: data), (response as? HTTPURLResponse)?.statusCode == 200 else { | |
completionHandler(nil, ImageDownloadError.invalidMetadata) | |
return | |
} | |
let detailedImage = DetailedImage(image: image, metadata: metadata) | |
completionHandler(detailedImage, nil) | |
} | |
metadataTask.resume() |
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
func downloadMetadata(for id: Int) async throws -> ImageMetadata { | |
let metadataUrl = URL(string: "https://www.andyibanez.com/fairesepages.github.io/tutorials/async-await/part1/\(id).json")! | |
let metadataRequest = URLRequest(url: metadataUrl) | |
let (data, metadataResponse) = try await URLSession.shared.data(for: metadataRequest) | |
guard (metadataResponse as? HTTPURLResponse)?.statusCode == 200 else { | |
throw ImageDownloadError.invalidMetadata | |
} | |
return try JSONDecoder().decode(ImageMetadata.self, from: data) | |
} |