Created
November 21, 2021 03:06
-
-
Save kean/846eba91cf3471071760ec0db3ddc23e to your computer and use it in GitHub Desktop.
Code from "Designing an API Client in Swift"
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
enum APIEnvironment: String, CaseIterable { | |
case dev | |
case test | |
case stage | |
case prod | |
} | |
struct ContentView: View { | |
@State private var selection: APIEnvironment? = env | |
var body: some View { | |
List(selection: $selection) { | |
ForEach(APIEnvironment.allCases, id: \.self, content: makeView) | |
} | |
.environment(\.editMode, .constant(EditMode.active)) | |
.navigationBarItems(trailing: Button("Save") { | |
DebugSettings.shared.environment = selection! | |
fatalError("Restarting the app") | |
}) | |
.disabled(selection == nil) | |
.navigationBarTitle("Environment") | |
} | |
private func makeView(for env: APIEnvironment) -> some View { | |
VStack(alignment: .leading) { | |
Text(env.rawValue) | |
.font(.headline) | |
Text(env.host) | |
.font(.footnote) | |
.foregroundColor(.secondary) | |
}.tag(env) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment