Created
December 25, 2021 08:33
-
-
Save pallavtrivedi03/e0363f4a6472c8e4ac40454588df25c9 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
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