Created
April 24, 2019 17:17
-
-
Save whoyawn/f7098b6ff10a6c178ac5e6f0ce308784 to your computer and use it in GitHub Desktop.
UserDefaults storage and the domains associated with them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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