Practical Swift Programs
Config Selection
Programs often choose one configuration for local runs and another for production.
Pick a configuration
config_selection.swift
let useProduction =
let localHost = "localhost"
let productionHost = "api.example.com"
let host = useProduction ? productionHost : localHost
let port = useProduction ? 443 : 8080
let endpoint = "\(host):\(port)"
print(endpoint)
let useProduction =
let localHost = "localhost"
let productionHost = "api.example.com"
let host = useProduction ? productionHost : localHost
let port = useProduction ? 443 : 8080
let endpoint = "\(host):\(port)"
print(endpoint)
configuration
A configuration value can select host names, ports, and other settings before the rest of a program starts.