ios Xcode 调试器不打印对象并显示 nil,当它们不是时
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19870176/
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
Xcode debugger doesn't print objects and shows nil, when they aren't
提问by Binarian
Xcode shows an error when trying to print an object with po <objectName>
, but only for one project.
Xcode 在尝试使用 打印对象时显示错误po <objectName>
,但仅针对一个项目。
error: Couldn't materialize struct: size of variable <varName> disagrees with the ValueObject's size Errored out in Execute, couldn't PrepareToExecuteJITExpression
错误:无法实现结构:变量 <varName> 的大小与 ValueObject 的大小不一致 在执行中出错,无法 PrepareToExecuteJITExpression
The Xcode debugger also shows ALL objects as nil
(self
excluded), when they aren't (NSLog
shows correct output, as seen in the image).
I don't know what's wrong with the project. Every other project works fine.
Xcode 调试器还将所有对象显示为nil
(self
排除),如果它们不是(NSLog
显示正确的输出,如图所示)。不知道项目出了什么问题。其他所有项目都运行良好。
Any idea what it could be? (Cleaning the project had no effect.)
知道它可能是什么吗?(清理项目没有效果。)
回答by Mick
Are you sure you are not in "Release mode"?
你确定你不是在“发布模式”?
If you want to see variable values you have to be in "Debug mode" (click on your project name on the top left corner near start/stop buttons, then "Edit scheme...", then "Run" settings, then "Info" tab, then "Build Configuration". Here set "Debug". If it was on "Release" that's the matter you saw all nils).
如果您想查看变量值,您必须处于“调试模式”(单击左上角开始/停止按钮附近的项目名称,然后单击“编辑方案...”,然后单击“运行”设置,然后单击“ Info”选项卡,然后是“Build Configuration”。在这里设置“Debug”。如果它在“Release”上,那你就看到了所有的 nils)。
回答by Leszek Zarna
I've set "Optimization Level" for Debug configuration to "None" and it solved problem.
我已将调试配置的“优化级别”设置为“无”,它解决了问题。
回答by KIO
Make sure that Address Sanitizer is turned off in your Scheme settings. The Address Sanitizer does not work well with the debugger.
确保在您的 Scheme 设置中关闭了 Address Sanitizer。Address Sanitizer 不适用于调试器。
- Go to Edit Scheme (Product >> Scheme >> Edit Scheme), choose Run, and go to the Diagnostics tab.
- Make sure "Enable Address Sanitizer" is off.
- 转到编辑方案(产品 >> 方案 >> 编辑方案),选择运行,然后转到诊断选项卡。
- 确保“启用地址清理程序”已关闭。
回答by LeiHao
It seems everyone has their own solution.
似乎每个人都有自己的解决方案。
For me, I use Objective-C
and Swift
at the same time.
对我来说,我同时使用Objective-C
和Swift
。
First of all, go to TARGETS -> Build Settings
and search the code generation
首先,去TARGETS -> Build Settings
搜索code generation
You'll find Apple LLVM 6.0
and Swift Compiler
你会发现Apple LLVM 6.0
和 Swift Compiler
Change their Optimization Level
all to None
, then Debug, you may find the value not nil
把它们Optimization Level
都None
改成 , 然后 Debug, 你可能会发现值不是nil
Amazingly once you can see the value, you solve this problem permanently, then you can change the Optimization Level
to it used to be.
令人惊讶的是,一旦您看到该值,您就永久解决了这个问题,然后您可以将其更改Optimization Level
为以前的状态。
回答by ThomasW
There are other ways this can occur. For me it was because the "Other C Flags" value was set to "-O2", even for the debug build. Turning this off for the debug build resolved the issue.
还有其他方式可能会发生这种情况。对我来说,这是因为“其他 C 标志”值设置为“-O2”,即使对于调试版本也是如此。为调试版本关闭此功能解决了该问题。
回答by Curmudgeonlybumbly
回答by Luke
I just encountered this issue and found that it was because Deployment Postprocessing = YES
in the Build Settings.
我刚刚遇到这个问题,发现是因为Deployment Postprocessing = YES
在Build Settings中。
Changing this to NO
fixed it, as seen in the screenshot below:
更改它以NO
修复它,如下面的屏幕截图所示:
Xcode version: 6.0.1 (6A317) on OSX 10.9.5
Xcode 版本:OSX 10.9.5 上的 6.0.1 (6A317)
回答by Torsten Barthel
I just run into a similar problem: At one point suddenly the Xcode debugger printed out some object types especially NSStrings as (null) although they were initialized with a value. Printed out via
我刚刚遇到了一个类似的问题:有一次 Xcode 调试器突然打印出一些对象类型,尤其是 NSStrings 为 (null),尽管它们是用一个值初始化的。通过打印
NSLog(@"String value: %@", myString);
the correct value for the object was shown.
显示了对象的正确值。
Confusing! Solving the problem was rather easy: I just shut down Xcode and restarted my computer. After I restarted Xcode everything works fine again :).
令人困惑!解决这个问题相当简单:我只是关闭了 Xcode 并重新启动了我的电脑。在我重新启动 Xcode 后,一切又正常了 :)。
回答by llama591
Make sure Link-Time Optimization = No
for debug mode in Build Settings.
确保Link-Time Optimization = No
在构建设置中使用调试模式。
回答by TMin
- Delete Derived Data
- Quite Xcode / Restart
- Clean Project
- 删除派生数据
- 相当 Xcode / 重新启动
- 清洁工程
That's all it took for me.
这就是我所需要的。