Created
March 8, 2021 17:58
-
-
Save lammertw/7f05c9bfc4206652ed9757f2162f861c to your computer and use it in GitHub Desktop.
This file contains 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 Combine | |
import SwiftUI | |
import shared | |
class ObservableRestaurantDetailViewModel: ObservableObject { | |
@Published var viewModelOutput: RestaurantDetailViewModelOutput? | |
init(viewModel: RestaurantDetailViewModel) { | |
asPublisher(viewModel.output) | |
.compactMap { $0 } | |
.receive(on: DispatchQueue.main) | |
.assign(to: &$viewModelOutput) | |
} | |
} | |
struct RestaurantDetailView: View { | |
@ObservedObject var viewModelOutput: ObservableRestaurantDetailViewModel | |
init(viewModel: RestaurantDetailViewModel) { | |
viewModelOutput = ObservableRestaurantDetailViewModel(viewModel: viewModel) | |
} | |
var body: some View { | |
if let output = viewModelOutput.viewModelOutput { | |
VStack { | |
Text(output.name) | |
Text(output.priceCategory) | |
// etc | |
} | |
} else { | |
EmptyView() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment