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")
Support Swift by Sundell by checking out this sponsor:
Essential Developer: Learn the most up-to-date techniques and strategies for testing new and legacy Swift code in this free practical course for developers who want to become complete senior iOS developers. This virtual event includes lectures, mentoring sessions, and step-by-step instructions. Click to learn more.