Skip to content

Instantly share code, notes, and snippets.

@paulweichhart
Created October 7, 2020 13:31
Show Gist options
  • Save paulweichhart/0bed2f8e2b7e85f6ea38863b04710a07 to your computer and use it in GitHub Desktop.
Save paulweichhart/0bed2f8e2b7e85f6ea38863b04710a07 to your computer and use it in GitHub Desktop.
import Foundation
import SwiftUI
final class Coordinator: ObservableObject {
enum Destination {
case loadingView
case rootView
case shareView(symbol: Symbol)
}
struct DestinationView: View {
let destination: Destination
weak var networkLayer: NetworkLayer?
var body: some View {
switch destination {
case .loadingView:
Text("Portfolio")
case let .shareView(symbol):
let viewModel = ShareViewModel(symbol: symbol, networkLayer: networkLayer)
ShareView(viewModel: viewModel)
case .rootView:
let viewModel = PortfolioViewModel(networkLayer: networkLayer)
PortfolioView(viewModel: viewModel)
}
}
}
private weak var networkLayer: NetworkLayer?
init(networkLayer: NetworkLayer?) {
self.networkLayer = networkLayer
}
func navigate(to destination: Destination) -> DestinationView {
return DestinationView(destination: destination, networkLayer: networkLayer)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment