xcode 如何找到Xcode中发生哪一行错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35346729/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:31:45  来源:igfitidea点击:

How to find which line error occurs in Xcode?

iosxcodeswift

提问by Harshil.Chokshi

I get an error "fatal error: unexpectedly found nil while unwrapping an Optional value" while running my app and I do not know where in the app the error has occurred.

我在运行我的应用程序时收到错误“致命错误:在解包可选值时意外发现 nil”,我不知道错误发生在应用程序的哪个位置。

I have two view controllers, and the error for sure doesn't occur in the first view controller because the view of the second controller appears and I also tested with break points in view will appear in the second view controller and everything works fine.

我有两个视图控制器,并且错误肯定不会发生在第一个视图控制器中,因为出现了第二个控制器的视图,并且我还测试了视图中的断点将出现在第二个视图控制器中,并且一切正常。

But now I do not know where to put breakpoints in the second view controller. Up to viewDidLoadand viewWillAppeareverything works fine, but at the didRecievememoryWarningmethod the error comes back up again.

但是现在我不知道在第二个视图控制器中放置断点的位置。直到viewDidLoadviewWillAppear一切正常,但在didRecievememoryWarning方法中,错误再次出现。

Do I have to place break points all over the file and find out which line is causing the error, or is there a quicker way to find out which is the exact line that is causing the error.

我是否必须在整个文件中放置断点并找出导致错误的行,还是有更快的方法来找出导致错误的确切行。

回答by Chris Slowik

That crash should show up in the debug navigator. It shows you the instruction that caused the crash.

该崩溃应显示在调试导航器中。它向您显示导致崩溃的指令。

enter image description here

在此处输入图片说明