有没有一种方法可以获取NSUserDefaults中的所有值? [英] Is there a way to get all values in NSUserDefaults?
本文介绍了有没有一种方法可以获取NSUserDefaults中的所有值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想打印通过NSUserDefaults
保存的所有值,而无需提供特定的密钥.
I would like to print all values I saved via NSUserDefaults
without supplying a specific Key.
类似于使用for
循环在数组中打印所有值的事情.有办法吗?
Something like printing all values in an array using for
loop. Is there a way to do so?
推荐答案
目标C
所有值:
NSLog(@"%@", [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allValues]);
所有键:
NSLog(@"%@", [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allKeys]);
所有键和值:
NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);
用于:
NSArray *keys = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allKeys];
for(NSString* key in keys){
// your code here
NSLog(@"value: %@ forKey: %@",[[NSUserDefaults standardUserDefaults] valueForKey:key],key);
}
快速
所有值:
print(UserDefaults.standard.dictionaryRepresentation().values)
所有键:
print(UserDefaults.standard.dictionaryRepresentation().keys)
所有键和值:
print(UserDefaults.standard.dictionaryRepresentation())
这篇关于有没有一种方法可以获取NSUserDefaults中的所有值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文