How do you print all the content of NSUserDefaults? I need to see everything that has been stored into NSUserDefaults. Is there a simple way to print that or to see it into the logs?
In Swift!
Thank you
Taken from - Retrieve UserDefaults in Swift
for (key, value) in UserDefaults.standard.dictionaryRepresentation() {
print("\(key) = \(value) \n")
}
print(Array(UserDefaults.standard.dictionaryRepresentation()))
// Using dump since the keys are an array of strings.
dump(Array(UserDefaults.standard.dictionaryRepresentation().keys))
We can use dump here as well, but that will return the complete inheritance hierarchy of each element in the values array. If more information about the objects is required, then use dump, else go ahead with the normal print statement.
// dump(Array(UserDefaults.standard.dictionaryRepresentation().values))
print(Array(UserDefaults.standard.dictionaryRepresentation().values))
print(NSUserDefaults.standardUserDefaults().dictionaryRepresentation())
print(NSUserDefaults.standardUserDefaults().dictionaryRepresentation().keys.array)
print(NSUserDefaults.standardUserDefaults().dictionaryRepresentation().values.array)
for elem in NSUserDefaults.standardUserDefaults().dictionaryRepresentation() {
println(elem)
}
以下是获取Swift 3中所有标准用户默认值的语法
print(UserDefaults.standard().dictionaryRepresentation())
With Swift 3.0
print(UserDefaults.standard.dictionaryRepresentation())
Here is the syntax that provide more clarity.
let defaults = UserDefaults.standard
defaults.dictionaryRepresentation().map{print("\($0.key): \($0.value)")}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.