Using shared UserDefaults suites
UserDefaults is a lot more powerful than what it first might seem like. Not only can it store more complex values (like dates and dictionaries) and parse command line arguments - it also enables easy sharing of settings & lightweight data between apps in the same App Group.
let sharedDefaults = UserDefaults(suiteName: "my-app-group")! let useDarkMode = sharedDefaults.bool(forKey: "dark-mode") // This value is put into the shared suite. sharedDefaults.set(true, forKey: "dark-mode") // If you want to treat the shared settings as read-only (and add // local overrides on top of them), you can simply add the shared // suite to the standard UserDefaults. let combinedDefaults = UserDefaults.standard combinedDefaults.addSuite(named: "my-app-group") // This value is a local override, not added to the shared suite. combinedDefaults.set(true, forKey: "app-specific-override")
For two weeks, many websites around the Swift community are featuring indie developers who have been financially impacted by the current pandemic. If you can, please help support these indies by downloading their apps. Today’s app is...
Endless Paper: An infinite (yes, really!) iPad canvas for you to draw, sketch ideas, and organize your work on — which you can then also broadcast as an online whiteboard. Features a custom Metal rendering engine and rock-solid performance.