Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Code from "Designing an API Client in Swift"
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(
.navigationBarItems(trailing: Button("Save") {
DebugSettings.shared.environment = selection!
fatalError("Restarting the app")
.disabled(selection == nil)
private func makeView(for env: APIEnvironment) -> some View {
VStack(alignment: .leading) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment