Parsing command line arguments using UserDefaults
A really cool "hidden" feature of UserDefaults is that it contains any arguments that were passed to the app at launch!
Super useful both in Swift command line tools and scripts, but also to temporarily override a value when debugging iOS apps.
let defaults = UserDefaults.standard let query = defaults.string(forKey: "query") let resultCount = defaults.integer(forKey: "results")
This ad keeps all of Swift by Sundell free for everyone. If you can, please check this sponsor out, as that directly helps support this site:
Bitrise: My favorite continuous integration service. Automatically build, test and distribute your app on every Pull Request — which is perfect for teams that are now working remotely, as you’ll quickly get feedback on each change that you make. Try out their new, improved free tier to get started.