有没有办法让NSUserDefaults中的所有值?
我想打印所有通过NSUserDefaults保存的值而不提供特定的键。 
 就像使用for循环打印数组中的所有值一样。 有没有办法做到这一点? 
目标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 *defaults = [NSUserDefaults standardUserDefaults]; NSDictionary *defaultAsDic = [defaults dictionaryRepresentation]; NSArray *keyArr = [defaultAsDic allKeys]; for (NSString *key in keyArr) { NSLog(@"key [%@] => Value [%@]",key,[defaultAsDic valueForKey:key]); } 
仅打印密钥
 NSLog(@"%@", [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allKeys]); 
键和值
 NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]); 
您可以使用以下方式logging所有可用的内容:
 NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);