你能在 xcode 调试器的任何地方看到 NSUserDefaults 的值吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3039769/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can you see the values of NSUserDefaults anywhere in the xcode debugger?
提问by nickthedude
Can you see the values of NSUserDefaults naywhere in the xcode debugger?
你能在 xcode 调试器的任何地方看到 NSUserDefaults 的值吗?
Just wondering if this is possible?
只是想知道这是否可能?
Thanks,
谢谢,
Nick
缺口
回答by RickiG
I don't have a solution to view them in the debugger, but I can offer this:
我没有在调试器中查看它们的解决方案,但我可以提供:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSLog(@"%@", [defaults dictionaryRepresentation]);
For some caveman-debugging:)
对于一些穴居人调试:)
EDIT: As David suggest in the comment, we can now do this in the debugging console:
编辑:正如大卫在评论中所建议的,我们现在可以在调试控制台中执行此操作:
po [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]
Swift 3.0
斯威夫特 3.0
po UserDefaults.standard.dictionaryRepresentation()
回答by TechZen
I haven't done it but you should be able to execute a po (print object) command on the user defaults like so:
我还没有这样做,但您应该能够对用户默认值执行 po(打印对象)命令,如下所示:
po [[NSUserDefaults standardUserDefaults] valueForKey:@"someKeyName"]
I prefer to wrap my defaults in a custom class and create a description method that dumps the defaults.
我更喜欢将我的默认值包装在一个自定义类中并创建一个转储默认值的描述方法。
You can use the "defaults" command line utility to examine the defaults exactly. Read the man page for details.
您可以使用“defaults”命令行实用程序来准确检查默认值。阅读手册页了解详细信息。
回答by typeoneerror
Not aware of any GUI that displays NSUserDefaults, but I use this in my application delegate to see the settings at start up:
不知道任何显示 NSUserDefaults 的 GUI,但我在我的应用程序委托中使用它来查看启动时的设置:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSLog(@"%@ DEFAULTS = %@", [self class], [defaults persistentDomainForName:[[NSBundle mainBundle] bundleIdentifier]]);
}
回答by Aks
You can log or either use PO command at debugger for Keys :
您可以在 Keys 的调试器中记录或使用 PO 命令:
NSLog(@"%@", [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allKeys]);
or for Keys and values:
或对于键和值:
NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);
& on debugger use: getting all keys :
& 在调试器上使用:获取所有密钥:
po [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allKeys]
for key & values :
对于键和值:
po [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]