快速跟踪“意外发现为零"到源头 [英] swift trace "unexpectedly found nil" to the source

查看:26
本文介绍了快速跟踪“意外发现为零"到源头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法找出哪个对象是 Nil?我在编码时不时遇到这些错误,通常我可以轻松找到它们,因为我经常测试我的代码.

Is there a way to find out which object is Nil? I get these errors from time to time while coding and normally I have no trouble finding them because I test my code frequently.

老问题,值得清理/额外信息.

Old question and deserved a clean up / extra info.

在我问这个问题的时候,我还没有真正理解什么是可选的.如果您遇到标题中所述的错误,请阅读可选选项并展开它们.基本上使用 guard letif let 语句.

At the time I asked this, I had no real grasp of what optionals were. If you are having the error stated in the title, read up on optionals and unwrapping them. Basically use guard let and if let statements.

如果您是因为不知道如何使用 Xcode 中的调试工具而来到这里,下面的答案显示了您要去哪里的屏幕截图.底部左侧屏幕显示值列表,其中之一将为 Nil

If you are here because you simple don't know how to use the debug tools in Xcode, the answers below show screenshots of where to go. The left screen at the bottom shows a list of values, one of them will be Nil

推荐答案

当您遇到此错误时,您应该能够浏览下图中框中当前分配的值.查看左下角的框,您可以查看出错时当前分配的任何值.在这种情况下,错误来自尝试从不存在的文件中读取

When you run into this error you should be able to browse through current assigned values in the box in the picture below. look at the box on the bottom left, you can look at any currently assigned value at the time of error. in this case the error is from attempting to read from a file that does not exist

这里有一个更好的例子

Here is a better example

这篇关于快速跟踪“意外发现为零"到源头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆