Created
October 7, 2020 13:31
-
-
Save paulweichhart/0bed2f8e2b7e85f6ea38863b04710a07 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 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