Skip to content

Instantly share code, notes, and snippets.

@whoyawn
Created April 24, 2019 17:17
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 whoyawn/f7098b6ff10a6c178ac5e6f0ce308784 to your computer and use it in GitHub Desktop.
Save whoyawn/f7098b6ff10a6c178ac5e6f0ce308784 to your computer and use it in GitHub Desktop.
UserDefaults storage and the domains associated with them
import Foundation
print(UserDefaults.argumentDomain) // NSArgumentDomain
print(UserDefaults.globalDomain) // NSGlobalDomain
print(UserDefaults.registrationDomain) // NSRegistrationDomain
let defaults = UserDefaults.standard
defaults.set("This is a test", forKey: "name")
let readString = defaults.string(forKey: "name")
print(readString!)
// standard stores stuff in the domain associated with the main identifier. In an app, it's the main bundle.
UserDefaults.standard.removePersistentDomain(forName: Bundle.main.bundleIdentifier!) // com.apple.dt.playground.stub.iOS_Simulator.MyPlayground-201A9570-1E46-44D6-9984-AA9624F46360"
defaults.dictionaryRepresentation() // everything in standard
defaults.string(forKey: "name")
Bundle.main.bundleIdentifier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment