Ali*_*kar 62 iphone objective-c nsuserdefaults ios ios6
我想打印我保存的所有值,NSUserDefaults而不提供特定的密钥.
像使用for循环打印数组中的所有值的东西.有办法吗?
小智 181
目标C.
所有价值观:
NSLog(@"%@", [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allValues]);
Run Code Online (Sandbox Code Playgroud)
所有键:
NSLog(@"%@", [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allKeys]);
Run Code Online (Sandbox Code Playgroud)
所有键和值:
NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);
Run Code Online (Sandbox Code Playgroud)
用于:
NSArray *keys = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allKeys];
for(NSString* key in keys){
// your code here
NSLog(@"value: %@ forKey: %@",[[NSUserDefaults standardUserDefaults] valueForKey:key],key);
}
Run Code Online (Sandbox Code Playgroud)
迅速
所有价值观:
print(UserDefaults.standard.dictionaryRepresentation().values)
Run Code Online (Sandbox Code Playgroud)
所有键:
print(UserDefaults.standard.dictionaryRepresentation().keys)
Run Code Online (Sandbox Code Playgroud)
所有键和值:
print(UserDefaults.standard.dictionaryRepresentation())
Run Code Online (Sandbox Code Playgroud)
仅打印按键
NSLog(@"%@", [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allKeys]);
Run Code Online (Sandbox Code Playgroud)
键和值
NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);
Run Code Online (Sandbox Code Playgroud)
您可以使用:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDictionary *defaultAsDic = [defaults dictionaryRepresentation];
NSArray *keyArr = [defaultAsDic allKeys];
for (NSString *key in keyArr)
{
NSLog(@"key [%@] => Value [%@]",key,[defaultAsDic valueForKey:key]);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
38323 次 |
| 最近记录: |