ios Swift 错误:向 SIGABRT 发出信号如何解决它

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

Swift error : signal SIGABRT how to solve it

iosswift

提问by chucklai

I'm just a beginner in Swift coding. My idea is quite simple which is an app with two buttons. When clicked, a textfield will change its text. In the Main.StoryBoard, I add a textfield and two buttons. In ViewController.swift file. I write as this:

我只是 Swift 编码的初学者。我的想法很简单,它是一个带有两个按钮的应用程序。单击时,文本字段将更改其文本。在 Main.StoryBoard 中,我添加了一个文本字段和两个按钮。在 ViewController.swift 文件中。我这样写:

import UIKit

class ViewController: UIViewController {
    @IBOutlet weak var textfield: UITextField!
    @IBOutlet weak var button: UIButton!
    @IBOutlet weak var button2: UIButton!

    @IBAction func action1(_ sender: UIButton) {
        textfield.text="you just clicked on button1"
    }
    @IBAction func action2(_ sender: UIButton) {
        textfield.text="you just clicked on button2"
    }
}

It is supposed to be all right. However, an error appears which shows:

应该没问题。但是,会出现一个错误,显示:

thread1:signal SIGABRT

线程 1:信号 SIGABRT

in file AppDelegate.swift line:

在文件 AppDelegate.swift 行中:

class AppDelegate: UIResponder, UIApplicationDelegate

What is wrong with my code?

我的代码有什么问题?

采纳答案by Marwan Salim

To solve the problem, first cleanthe project and then rebuild.

要解决这个问题,首先清理项目,然后 重建.

To clean the project, go to MenuBar: Product -> Clean

要清理项目,请转到菜单栏:产品 -> 清理

Then to rebuild the project, just click the Run button as usual.

然后要重建项目,只需像往常一样单击“运行”按钮。

回答by Andy Lebowitz

You get a SIGABRT error whenever you have a disconnected outlet. Click on your view controller in the storyboard and go to connections in the side panel (the arrow symbol). See if you have an extra outlet there, a duplicate, or an extra one that's not connected. If it's not that then maybe you haven't connected your outlets to your code correctly.

每当您的插座断开连接时,您都会收到 SIGABRT 错误。单击故事板中的视图控制器,然后转到侧面板中的连接(箭头符号)。看看那里是否有额外的插座、重复的或未连接的额外插座。如果不是这样,那么您可能没有正确地将插座连接到您的代码。

Just remember that SIGABRT happens when you are trying to call an outlet (button, view, textfield, etc) that isn't there.

请记住,当您尝试调用不存在的插座(按钮、视图、文本字段等)时,会发生 SIGABRT。

回答by dangalg

For me it wasn't an outlet. I solved the problem by going to the error And reading what it said. (Also Noob..)

对我来说,这不是一个出口。我通过转到错误并阅读它所说的内容来解决问题。(也是菜鸟..)

This was the error:

这是错误:

enter image description here

在此处输入图片说明

And The solution was here: enter image description here

解决方案在这里: 在此处输入图片说明

Just scroll up in the output and the error will be revealed.

只需在输出中向上滚动,就会显示错误。

回答by Anshu Shahi

A common reason for this type of error is that you might have changed the name of your IBOutlet or IBAction you can simply check this by going to source code.

此类错误的一个常见原因是您可能更改了 IBOutlet 或 IBAction 的名称,您可以通过访问源代码来简单地进行检查。

Click on the main.storyboardand then select open asand then select source codeenter image description here

点击main.storyboard然后选择open as然后选择source code在此处输入图片说明

source code will open

源代码将打开

and then check whether there is the name of the iboutlet or ibaction that you have changed , if there is then select the part and delete it and then again create iboutlet or ibaction. This should resolve your problem

然后检查是否有你改过的iboutlet或ibaction的名称,如果有则选择该部分并删除它,然后再次创建iboutlet或ibaction。这应该可以解决您的问题

回答by GOrozco58

In my case I wasn't getting error just the crash in the AppDelegate and I had to uncheck the next option: OS_ACTIVITY_MODEthen I could get the real crash reason in my .xib file

在我的情况下,我没有得到错误只是 AppDelegate 中的崩溃,我不得不取消选中下一个选项:OS_ACTIVITY_MODE然后我可以在我的 .xib 文件中获得真正的崩溃原因

enter image description here

在此处输入图片说明

Hope this can help you too :)

希望这也能帮助你:)

回答by Bijan Negari

I had the same problem. I made a button in the storyboard and connected it to the ViewController, and then later on deleted the button. So the connection was still there, but the button was not, and so I got the same error as you.

我有同样的问题。我在情节提要中创建了一个按钮并将其连接到 ViewController,然后删除了该按钮。所以连接仍然存在,但按钮没有,所以我遇到了和你一样的错误。

To Fix:

修理:

Go to the connection inspector (the arrow in the top right corner, in your storyboard), and delete any unused connections.

转到连接检查器(右上角的箭头,在故事板中),并删除所有未使用的连接。

回答by Jon Vogel

If you run into this in Xcode 10 you will have to clean before build. Or, switch to the legacy build system. File -> Workspace Settings... -> Build System: Legacy Build System.

如果您在 Xcode 10 中遇到此问题,则必须在构建前进行清理。或者,切换到旧版构建系统。文件 -> 工作区设置... -> 构建系统:传统构建系统。

回答by Bishnu Das

Sometimes it also happens when the function need to be executed in main thread only, so you can fix it by assigning it to the main thread as follows :-

有时当函数只需要在主线程中执行时也会发生这种情况,因此您可以通过将其分配给主线程来修复它,如下所示:-

DispatchQueue.main.async{
  your code here
}

回答by JonesJr876

For me, This error was because i had a prepare segue step that wasn't applicable to the segue that was being done.

对我来说,这个错误是因为我有一个不适用于正在完成的 segue 的准备 segue 步骤。

long story:

很长的故事:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

        let gosetup = segue.destination as! Update
        gosetup.wherefrom = updatestring

    }

This was being done to all segue when it was only for one. So i create a boolean and placed the gosetup inside it.

当它仅用于一个时,这对所有segue都进行了。所以我创建了一个布尔值并将 gosetup 放在里面。

回答by Xavier Lowmiller

In my case there was no log whatsoever.

就我而言,没有任何日志。

My mistake was to push a view controller in a navigation stack that was already part of the navigation stack.

我的错误是将视图控制器推送到已经是导航堆栈一部分的导航堆栈中。