Xcode 错误线程 1:EXC_BREAKPOINT(代码=1,子代码=0x1001f276588)

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

Xcode error Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1001f276588)

iosxcode

提问by atirit

I get the titular error when running my project on an actual device. Sometimes the subcode varies. I don't have ANY breakpoints. I checked. Trust me on that.

在实际设备上运行我的项目时出现名义错误。有时子代码会有所不同。我没有任何断点。我检查了。相信我。

enter image description here

在此处输入图片说明

Here are my files. This error happens on launch.

这是我的文件。此错误发生在启动时。

What can I do to fix this? Thanks in advance!

我能做些什么来解决这个问题?提前致谢!

EDIT: fatal error: unexpectedly found nil while unwrapping an Optional valueis printed to the console.

编辑:fatal error: unexpectedly found nil while unwrapping an Optional value打印到控制台。

回答by Robski18

I think the error is in this part:

我认为错误在这部分:

let dir = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.AllDomainsMask, true).first 
let filePath = NSURL(fileURLWithPath: dir!).URLByAppendingPathComponent("file.txt")

It is forced to unwrap "dir", which is probably not available in this case on your actual device. This causes the immediate crash.

它被迫解开“dir”,在这种情况下,这可能在您的实际设备上不可用。这会导致立即崩溃。

回答by atirit

I found the problem: I was trying to use a variable that was nil. I know that's what the debugger message says, but I figured out which one.

我发现了问题:我试图使用一个为零的变量。我知道这就是调试器消息所说的,但我想出了哪个。

enter image description here

在此处输入图片说明

Oh well. I messed up. Thanks to everyone for all their help!

那好吧。我搞砸了。感谢大家的帮助!