Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barbaramartina/71d54fb329f34b0bb7e3c7ebc166fa77 to your computer and use it in GitHub Desktop.
Save barbaramartina/71d54fb329f34b0bb7e3c7ebc166fa77 to your computer and use it in GitHub Desktop.
/// This is how you could use standar user defaults for sharing app between your app and your extensions.
/// You should have groups capability enable in your app and extensions and use the same group name everywhere.
/// For more info see: https://developer.apple.com/library/content/documentation/IDEs/Conceptual/AppDistributionGuide/AddingCapabilities/AddingCapabilities.html
/// -initWithSuiteName: initializes an instance of NSUserDefaults that searches the shared preferences search list for the domain 'suitename'. For example, using the identifier of an application group will cause the receiver to search the preferences for that group. Passing the current application's bundle identifier, NSGlobalDomain, or the corresponding CFPreferences constants is an error. Passing nil will search the default search list.
if let defaults = UserDefaults(suiteName: "yourapp.group.name") {
defaults.set("VALUE", forKey: "KEY")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment