Skip to content

Instantly share code, notes, and snippets.

@EvolverSwiftUI
Forked from pallavtrivedi03/ZipOperator.swift
Created February 11, 2022 18:13
Show Gist options
  • Save EvolverSwiftUI/eee377c89d6202041308b28fe9631928 to your computer and use it in GitHub Desktop.
Save EvolverSwiftUI/eee377c89d6202041308b28fe9631928 to your computer and use it in GitHub Desktop.
import Foundation
import Combine
class SignUpViewModel: ObservableObject {
@Published var userProfile: UserProfileModel?
private var cancellables = Set<AnyCancellable>()
func getOnboardingData() {
let publishers = Publishers.Zip(
getPublisher(for: SignUpCouponsModel.self, url: URLList.coupons),
getPublisher(for: SignUpProfileModel.self, url: URLList.profile)
)
publishers.map { (couponsModel, profileModel) in
UserProfileModel(profileData: profileModel, rewardedCoupons: [couponsModel])
}
.sink { (completion) in
if case let .failure(error) = completion {
print("Error -> \(error.localizedDescription)")
}
} receiveValue: { [weak self] profileModel in
self?.userProfile = profileModel
}
.store(in: &cancellables)
}
func getPublisher<T: Decodable>(for type: T.Type, url: String) -> Future<T, Error> {
NetworkManager.shared.getData(url: url, type: T.self)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment